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 alloc::string::String;
22 use core::ffi::c_void;
23 use core::convert::Infallible;
24 use bitcoin::hashes::Hash;
25 use crate::c_types::*;
26 #[cfg(feature="no-std")]
27 use alloc::{vec::Vec, boxed::Box};
34 use alloc::str::FromStr;
35 use alloc::string::String;
36 use core::ffi::c_void;
37 use core::convert::Infallible;
38 use bitcoin::hashes::Hash;
39 use crate::c_types::*;
40 #[cfg(feature="no-std")]
41 use alloc::{vec::Vec, boxed::Box};
45 use alloc::str::FromStr;
46 use alloc::string::String;
47 use core::ffi::c_void;
48 use core::convert::Infallible;
49 use bitcoin::hashes::Hash;
50 use crate::c_types::*;
51 #[cfg(feature="no-std")]
52 use alloc::{vec::Vec, boxed::Box};
56 /// Read a SiPrefix object from a string
57 pub extern "C" fn SiPrefix_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SiPrefixBolt11ParseErrorZ {
58 match lightning_invoice::SiPrefix::from_str(s.into_str()) {
60 crate::c_types::CResultTempl::ok(
61 crate::lightning_invoice::SiPrefix::native_into(r)
65 crate::c_types::CResultTempl::err(
66 crate::lightning_invoice::Bolt11ParseError::native_into(e)
72 /// Read a Bolt11Invoice object from a string
73 pub extern "C" fn Bolt11Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_Bolt11InvoiceParseOrSemanticErrorZ {
74 match lightning_invoice::Bolt11Invoice::from_str(s.into_str()) {
76 crate::c_types::CResultTempl::ok(
77 crate::lightning_invoice::Bolt11Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
81 crate::c_types::CResultTempl::err(
82 crate::lightning_invoice::ParseOrSemanticError::native_into(e)
88 /// Read a SignedRawBolt11Invoice object from a string
89 pub extern "C" fn SignedRawBolt11Invoice_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SignedRawBolt11InvoiceBolt11ParseErrorZ {
90 match lightning_invoice::SignedRawBolt11Invoice::from_str(s.into_str()) {
92 crate::c_types::CResultTempl::ok(
93 crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(r), is_owned: true }
97 crate::c_types::CResultTempl::err(
98 crate::lightning_invoice::Bolt11ParseError::native_into(e)
104 /// Get the string representation of a Bolt11ParseError object
105 pub extern "C" fn Bolt11ParseError_to_str(o: &crate::lightning_invoice::Bolt11ParseError) -> Str {
106 alloc::format!("{}", &o.to_native()).into()
109 /// Get the string representation of a ParseOrSemanticError object
110 pub extern "C" fn ParseOrSemanticError_to_str(o: &crate::lightning_invoice::ParseOrSemanticError) -> Str {
111 alloc::format!("{}", &o.to_native()).into()
116 use alloc::str::FromStr;
117 use alloc::string::String;
118 use core::ffi::c_void;
119 use core::convert::Infallible;
120 use bitcoin::hashes::Hash;
121 use crate::c_types::*;
122 #[cfg(feature="no-std")]
123 use alloc::{vec::Vec, boxed::Box};
126 /// Get the string representation of a Bolt11Invoice object
127 pub extern "C" fn Bolt11Invoice_to_str(o: &crate::lightning_invoice::Bolt11Invoice) -> Str {
128 alloc::format!("{}", o.get_native_ref()).into()
131 /// Get the string representation of a SignedRawBolt11Invoice object
132 pub extern "C" fn SignedRawBolt11Invoice_to_str(o: &crate::lightning_invoice::SignedRawBolt11Invoice) -> Str {
133 alloc::format!("{}", o.get_native_ref()).into()
136 /// Get the string representation of a Currency object
137 pub extern "C" fn Currency_to_str(o: &crate::lightning_invoice::Currency) -> Str {
138 alloc::format!("{}", &o.to_native()).into()
141 /// Get the string representation of a SiPrefix object
142 pub extern "C" fn SiPrefix_to_str(o: &crate::lightning_invoice::SiPrefix) -> Str {
143 alloc::format!("{}", &o.to_native()).into()
148 use alloc::str::FromStr;
149 use alloc::string::String;
150 use core::ffi::c_void;
151 use core::convert::Infallible;
152 use bitcoin::hashes::Hash;
153 use crate::c_types::*;
154 #[cfg(feature="no-std")]
155 use alloc::{vec::Vec, boxed::Box};
160 use alloc::str::FromStr;
161 use alloc::string::String;
162 use core::ffi::c_void;
163 use core::convert::Infallible;
164 use bitcoin::hashes::Hash;
165 use crate::c_types::*;
166 #[cfg(feature="no-std")]
167 use alloc::{vec::Vec, boxed::Box};
172 use alloc::str::FromStr;
173 use alloc::string::String;
174 use core::ffi::c_void;
175 use core::convert::Infallible;
176 use bitcoin::hashes::Hash;
177 use crate::c_types::*;
178 #[cfg(feature="no-std")]
179 use alloc::{vec::Vec, boxed::Box};
182 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
183 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
187 pub enum Bolt11ParseError {
189 crate::c_types::Bech32Error),
191 crate::c_types::Error),
193 crate::c_types::Secp256k1Error),
199 UnexpectedEndOfTaggedFields,
200 DescriptionDecodeError(
201 crate::c_types::Error),
203 IntegerOverflowError,
204 InvalidSegWitProgramLength,
205 InvalidPubKeyHashLength,
206 InvalidScriptHashLength,
209 crate::c_types::Str),
210 /// Not an error, but used internally to signal that a part of the invoice should be ignored
211 /// according to BOLT11
214 use lightning_invoice::Bolt11ParseError as Bolt11ParseErrorImport;
215 pub(crate) type nativeBolt11ParseError = Bolt11ParseErrorImport;
217 impl Bolt11ParseError {
219 pub(crate) fn to_native(&self) -> nativeBolt11ParseError {
221 Bolt11ParseError::Bech32Error (ref a, ) => {
222 let mut a_nonref = Clone::clone(a);
223 nativeBolt11ParseError::Bech32Error (
224 a_nonref.into_rust(),
227 Bolt11ParseError::ParseAmountError (ref a, ) => {
228 let mut a_nonref = Clone::clone(a);
229 nativeBolt11ParseError::ParseAmountError (
230 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
233 Bolt11ParseError::MalformedSignature (ref a, ) => {
234 let mut a_nonref = Clone::clone(a);
235 nativeBolt11ParseError::MalformedSignature (
236 a_nonref.into_rust(),
239 Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
240 Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
241 Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
242 Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
243 Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
244 Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
245 Bolt11ParseError::DescriptionDecodeError (ref a, ) => {
246 let mut a_nonref = Clone::clone(a);
247 nativeBolt11ParseError::DescriptionDecodeError (
248 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
251 Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
252 Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
253 Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
254 Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
255 Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
256 Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
257 Bolt11ParseError::InvalidSliceLength (ref a, ) => {
258 let mut a_nonref = Clone::clone(a);
259 nativeBolt11ParseError::InvalidSliceLength (
260 a_nonref.into_string(),
263 Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
267 pub(crate) fn into_native(self) -> nativeBolt11ParseError {
269 Bolt11ParseError::Bech32Error (mut a, ) => {
270 nativeBolt11ParseError::Bech32Error (
274 Bolt11ParseError::ParseAmountError (mut a, ) => {
275 nativeBolt11ParseError::ParseAmountError (
276 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
279 Bolt11ParseError::MalformedSignature (mut a, ) => {
280 nativeBolt11ParseError::MalformedSignature (
284 Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
285 Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
286 Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
287 Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
288 Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
289 Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
290 Bolt11ParseError::DescriptionDecodeError (mut a, ) => {
291 nativeBolt11ParseError::DescriptionDecodeError (
292 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
295 Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
296 Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
297 Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
298 Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
299 Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
300 Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
301 Bolt11ParseError::InvalidSliceLength (mut a, ) => {
302 nativeBolt11ParseError::InvalidSliceLength (
306 Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
310 pub(crate) fn from_native(native: &nativeBolt11ParseError) -> Self {
312 nativeBolt11ParseError::Bech32Error (ref a, ) => {
313 let mut a_nonref = Clone::clone(a);
314 Bolt11ParseError::Bech32Error (
315 crate::c_types::Bech32Error::from_rust(a_nonref),
318 nativeBolt11ParseError::ParseAmountError (ref a, ) => {
319 let mut a_nonref = Clone::clone(a);
320 Bolt11ParseError::ParseAmountError (
321 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
324 nativeBolt11ParseError::MalformedSignature (ref a, ) => {
325 let mut a_nonref = Clone::clone(a);
326 Bolt11ParseError::MalformedSignature (
327 crate::c_types::Secp256k1Error::from_rust(a_nonref),
330 nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
331 nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
332 nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
333 nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
334 nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
335 nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
336 nativeBolt11ParseError::DescriptionDecodeError (ref a, ) => {
337 let mut a_nonref = Clone::clone(a);
338 Bolt11ParseError::DescriptionDecodeError (
339 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
342 nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
343 nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
344 nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
345 nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
346 nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
347 nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
348 nativeBolt11ParseError::InvalidSliceLength (ref a, ) => {
349 let mut a_nonref = Clone::clone(a);
350 Bolt11ParseError::InvalidSliceLength (
354 nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
358 pub(crate) fn native_into(native: nativeBolt11ParseError) -> Self {
360 nativeBolt11ParseError::Bech32Error (mut a, ) => {
361 Bolt11ParseError::Bech32Error (
362 crate::c_types::Bech32Error::from_rust(a),
365 nativeBolt11ParseError::ParseAmountError (mut a, ) => {
366 Bolt11ParseError::ParseAmountError (
367 crate::c_types::Error { _dummy: 0 } /*a*/,
370 nativeBolt11ParseError::MalformedSignature (mut a, ) => {
371 Bolt11ParseError::MalformedSignature (
372 crate::c_types::Secp256k1Error::from_rust(a),
375 nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
376 nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
377 nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
378 nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
379 nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
380 nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
381 nativeBolt11ParseError::DescriptionDecodeError (mut a, ) => {
382 Bolt11ParseError::DescriptionDecodeError (
383 crate::c_types::Error { _dummy: 0 } /*a*/,
386 nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
387 nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
388 nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
389 nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
390 nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
391 nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
392 nativeBolt11ParseError::InvalidSliceLength (mut a, ) => {
393 Bolt11ParseError::InvalidSliceLength (
397 nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
401 /// Frees any resources used by the Bolt11ParseError
403 pub extern "C" fn Bolt11ParseError_free(this_ptr: Bolt11ParseError) { }
404 /// Creates a copy of the Bolt11ParseError
406 pub extern "C" fn Bolt11ParseError_clone(orig: &Bolt11ParseError) -> Bolt11ParseError {
410 /// Utility method to constructs a new Bech32Error-variant Bolt11ParseError
411 pub extern "C" fn Bolt11ParseError_bech32_error(a: crate::c_types::Bech32Error) -> Bolt11ParseError {
412 Bolt11ParseError::Bech32Error(a, )
415 /// Utility method to constructs a new ParseAmountError-variant Bolt11ParseError
416 pub extern "C" fn Bolt11ParseError_parse_amount_error(a: crate::c_types::Error) -> Bolt11ParseError {
417 Bolt11ParseError::ParseAmountError(a, )
420 /// Utility method to constructs a new MalformedSignature-variant Bolt11ParseError
421 pub extern "C" fn Bolt11ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> Bolt11ParseError {
422 Bolt11ParseError::MalformedSignature(a, )
425 /// Utility method to constructs a new BadPrefix-variant Bolt11ParseError
426 pub extern "C" fn Bolt11ParseError_bad_prefix() -> Bolt11ParseError {
427 Bolt11ParseError::BadPrefix}
429 /// Utility method to constructs a new UnknownCurrency-variant Bolt11ParseError
430 pub extern "C" fn Bolt11ParseError_unknown_currency() -> Bolt11ParseError {
431 Bolt11ParseError::UnknownCurrency}
433 /// Utility method to constructs a new UnknownSiPrefix-variant Bolt11ParseError
434 pub extern "C" fn Bolt11ParseError_unknown_si_prefix() -> Bolt11ParseError {
435 Bolt11ParseError::UnknownSiPrefix}
437 /// Utility method to constructs a new MalformedHRP-variant Bolt11ParseError
438 pub extern "C" fn Bolt11ParseError_malformed_hrp() -> Bolt11ParseError {
439 Bolt11ParseError::MalformedHRP}
441 /// Utility method to constructs a new TooShortDataPart-variant Bolt11ParseError
442 pub extern "C" fn Bolt11ParseError_too_short_data_part() -> Bolt11ParseError {
443 Bolt11ParseError::TooShortDataPart}
445 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant Bolt11ParseError
446 pub extern "C" fn Bolt11ParseError_unexpected_end_of_tagged_fields() -> Bolt11ParseError {
447 Bolt11ParseError::UnexpectedEndOfTaggedFields}
449 /// Utility method to constructs a new DescriptionDecodeError-variant Bolt11ParseError
450 pub extern "C" fn Bolt11ParseError_description_decode_error(a: crate::c_types::Error) -> Bolt11ParseError {
451 Bolt11ParseError::DescriptionDecodeError(a, )
454 /// Utility method to constructs a new PaddingError-variant Bolt11ParseError
455 pub extern "C" fn Bolt11ParseError_padding_error() -> Bolt11ParseError {
456 Bolt11ParseError::PaddingError}
458 /// Utility method to constructs a new IntegerOverflowError-variant Bolt11ParseError
459 pub extern "C" fn Bolt11ParseError_integer_overflow_error() -> Bolt11ParseError {
460 Bolt11ParseError::IntegerOverflowError}
462 /// Utility method to constructs a new InvalidSegWitProgramLength-variant Bolt11ParseError
463 pub extern "C" fn Bolt11ParseError_invalid_seg_wit_program_length() -> Bolt11ParseError {
464 Bolt11ParseError::InvalidSegWitProgramLength}
466 /// Utility method to constructs a new InvalidPubKeyHashLength-variant Bolt11ParseError
467 pub extern "C" fn Bolt11ParseError_invalid_pub_key_hash_length() -> Bolt11ParseError {
468 Bolt11ParseError::InvalidPubKeyHashLength}
470 /// Utility method to constructs a new InvalidScriptHashLength-variant Bolt11ParseError
471 pub extern "C" fn Bolt11ParseError_invalid_script_hash_length() -> Bolt11ParseError {
472 Bolt11ParseError::InvalidScriptHashLength}
474 /// Utility method to constructs a new InvalidRecoveryId-variant Bolt11ParseError
475 pub extern "C" fn Bolt11ParseError_invalid_recovery_id() -> Bolt11ParseError {
476 Bolt11ParseError::InvalidRecoveryId}
478 /// Utility method to constructs a new InvalidSliceLength-variant Bolt11ParseError
479 pub extern "C" fn Bolt11ParseError_invalid_slice_length(a: crate::c_types::Str) -> Bolt11ParseError {
480 Bolt11ParseError::InvalidSliceLength(a, )
483 /// Utility method to constructs a new Skip-variant Bolt11ParseError
484 pub extern "C" fn Bolt11ParseError_skip() -> Bolt11ParseError {
485 Bolt11ParseError::Skip}
486 /// Checks if two Bolt11ParseErrors contain equal inner contents.
487 /// This ignores pointers and is_owned flags and looks at the values in fields.
489 pub extern "C" fn Bolt11ParseError_eq(a: &Bolt11ParseError, b: &Bolt11ParseError) -> bool {
490 if &a.to_native() == &b.to_native() { true } else { false }
492 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
493 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
494 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
498 pub enum ParseOrSemanticError {
499 /// The invoice couldn't be decoded
501 crate::lightning_invoice::Bolt11ParseError),
502 /// The invoice could be decoded but violates the BOLT11 standard
504 crate::lightning_invoice::Bolt11SemanticError),
506 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
507 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
509 impl ParseOrSemanticError {
511 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
513 ParseOrSemanticError::ParseError (ref a, ) => {
514 let mut a_nonref = Clone::clone(a);
515 nativeParseOrSemanticError::ParseError (
516 a_nonref.into_native(),
519 ParseOrSemanticError::SemanticError (ref a, ) => {
520 let mut a_nonref = Clone::clone(a);
521 nativeParseOrSemanticError::SemanticError (
522 a_nonref.into_native(),
528 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
530 ParseOrSemanticError::ParseError (mut a, ) => {
531 nativeParseOrSemanticError::ParseError (
535 ParseOrSemanticError::SemanticError (mut a, ) => {
536 nativeParseOrSemanticError::SemanticError (
543 pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
545 nativeParseOrSemanticError::ParseError (ref a, ) => {
546 let mut a_nonref = Clone::clone(a);
547 ParseOrSemanticError::ParseError (
548 crate::lightning_invoice::Bolt11ParseError::native_into(a_nonref),
551 nativeParseOrSemanticError::SemanticError (ref a, ) => {
552 let mut a_nonref = Clone::clone(a);
553 ParseOrSemanticError::SemanticError (
554 crate::lightning_invoice::Bolt11SemanticError::native_into(a_nonref),
560 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
562 nativeParseOrSemanticError::ParseError (mut a, ) => {
563 ParseOrSemanticError::ParseError (
564 crate::lightning_invoice::Bolt11ParseError::native_into(a),
567 nativeParseOrSemanticError::SemanticError (mut a, ) => {
568 ParseOrSemanticError::SemanticError (
569 crate::lightning_invoice::Bolt11SemanticError::native_into(a),
575 /// Frees any resources used by the ParseOrSemanticError
577 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
578 /// Creates a copy of the ParseOrSemanticError
580 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
584 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
585 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::Bolt11ParseError) -> ParseOrSemanticError {
586 ParseOrSemanticError::ParseError(a, )
589 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
590 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::Bolt11SemanticError) -> ParseOrSemanticError {
591 ParseOrSemanticError::SemanticError(a, )
593 /// Checks if two ParseOrSemanticErrors contain equal inner contents.
594 /// This ignores pointers and is_owned flags and looks at the values in fields.
596 pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
597 if &a.to_native() == &b.to_native() { true } else { false }
599 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
601 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
604 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
605 /// Default expiry time as defined by [BOLT 11].
607 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
610 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
611 /// Default minimum final CLTV expiry as defined by [BOLT 11].
613 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
614 /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
616 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
617 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
620 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA;
622 use lightning_invoice::Bolt11Invoice as nativeBolt11InvoiceImport;
623 pub(crate) type nativeBolt11Invoice = nativeBolt11InvoiceImport;
625 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
627 /// There are three ways to construct a `Bolt11Invoice`:
628 /// 1. using [`InvoiceBuilder`]
629 /// 2. using [`Bolt11Invoice::from_signed`]
630 /// 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
632 /// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
635 pub struct Bolt11Invoice {
636 /// A pointer to the opaque Rust object.
638 /// Nearly everywhere, inner must be non-null, however in places where
639 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
640 pub inner: *mut nativeBolt11Invoice,
641 /// Indicates that this is the only struct which contains the same pointer.
643 /// Rust functions which take ownership of an object provided via an argument require
644 /// this to be true and invalidate the object pointed to by inner.
648 impl Drop for Bolt11Invoice {
650 if self.is_owned && !<*mut nativeBolt11Invoice>::is_null(self.inner) {
651 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
655 /// Frees any resources used by the Bolt11Invoice, if is_owned is set and inner is non-NULL.
657 pub extern "C" fn Bolt11Invoice_free(this_obj: Bolt11Invoice) { }
659 /// Used only if an object of this type is returned as a trait impl by a method
660 pub(crate) extern "C" fn Bolt11Invoice_free_void(this_ptr: *mut c_void) {
661 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11Invoice) };
665 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11Invoice {
666 unsafe { &*ObjOps::untweak_ptr(self.inner) }
668 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11Invoice {
669 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
671 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
672 pub(crate) fn take_inner(mut self) -> *mut nativeBolt11Invoice {
673 assert!(self.is_owned);
674 let ret = ObjOps::untweak_ptr(self.inner);
675 self.inner = core::ptr::null_mut();
679 /// Checks if two Bolt11Invoices contain equal inner contents.
680 /// This ignores pointers and is_owned flags and looks at the values in fields.
681 /// Two objects with NULL inner values will be considered "equal" here.
683 pub extern "C" fn Bolt11Invoice_eq(a: &Bolt11Invoice, b: &Bolt11Invoice) -> bool {
684 if a.inner == b.inner { return true; }
685 if a.inner.is_null() || b.inner.is_null() { return false; }
686 if a.get_native_ref() == b.get_native_ref() { true } else { false }
688 impl Clone for Bolt11Invoice {
689 fn clone(&self) -> Self {
691 inner: if <*mut nativeBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
692 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
698 /// Used only if an object of this type is returned as a trait impl by a method
699 pub(crate) extern "C" fn Bolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
700 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11Invoice)).clone() })) as *mut c_void
703 /// Creates a copy of the Bolt11Invoice
704 pub extern "C" fn Bolt11Invoice_clone(orig: &Bolt11Invoice) -> Bolt11Invoice {
707 /// Generates a non-cryptographic 64-bit hash of the Bolt11Invoice.
709 pub extern "C" fn Bolt11Invoice_hash(o: &Bolt11Invoice) -> u64 {
710 if o.inner.is_null() { return 0; }
711 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
713 let mut hasher = core::hash::SipHasher::new();
714 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
715 core::hash::Hasher::finish(&hasher)
718 use lightning_invoice::SignedRawBolt11Invoice as nativeSignedRawBolt11InvoiceImport;
719 pub(crate) type nativeSignedRawBolt11Invoice = nativeSignedRawBolt11InvoiceImport;
721 /// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
725 /// The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
728 pub struct SignedRawBolt11Invoice {
729 /// A pointer to the opaque Rust object.
731 /// Nearly everywhere, inner must be non-null, however in places where
732 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
733 pub inner: *mut nativeSignedRawBolt11Invoice,
734 /// Indicates that this is the only struct which contains the same pointer.
736 /// Rust functions which take ownership of an object provided via an argument require
737 /// this to be true and invalidate the object pointed to by inner.
741 impl Drop for SignedRawBolt11Invoice {
743 if self.is_owned && !<*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) {
744 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
748 /// Frees any resources used by the SignedRawBolt11Invoice, if is_owned is set and inner is non-NULL.
750 pub extern "C" fn SignedRawBolt11Invoice_free(this_obj: SignedRawBolt11Invoice) { }
752 /// Used only if an object of this type is returned as a trait impl by a method
753 pub(crate) extern "C" fn SignedRawBolt11Invoice_free_void(this_ptr: *mut c_void) {
754 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawBolt11Invoice) };
757 impl SignedRawBolt11Invoice {
758 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawBolt11Invoice {
759 unsafe { &*ObjOps::untweak_ptr(self.inner) }
761 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawBolt11Invoice {
762 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
764 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
765 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawBolt11Invoice {
766 assert!(self.is_owned);
767 let ret = ObjOps::untweak_ptr(self.inner);
768 self.inner = core::ptr::null_mut();
772 /// Checks if two SignedRawBolt11Invoices contain equal inner contents.
773 /// This ignores pointers and is_owned flags and looks at the values in fields.
774 /// Two objects with NULL inner values will be considered "equal" here.
776 pub extern "C" fn SignedRawBolt11Invoice_eq(a: &SignedRawBolt11Invoice, b: &SignedRawBolt11Invoice) -> bool {
777 if a.inner == b.inner { return true; }
778 if a.inner.is_null() || b.inner.is_null() { return false; }
779 if a.get_native_ref() == b.get_native_ref() { true } else { false }
781 impl Clone for SignedRawBolt11Invoice {
782 fn clone(&self) -> Self {
784 inner: if <*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
785 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
791 /// Used only if an object of this type is returned as a trait impl by a method
792 pub(crate) extern "C" fn SignedRawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
793 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSignedRawBolt11Invoice)).clone() })) as *mut c_void
796 /// Creates a copy of the SignedRawBolt11Invoice
797 pub extern "C" fn SignedRawBolt11Invoice_clone(orig: &SignedRawBolt11Invoice) -> SignedRawBolt11Invoice {
800 /// Generates a non-cryptographic 64-bit hash of the SignedRawBolt11Invoice.
802 pub extern "C" fn SignedRawBolt11Invoice_hash(o: &SignedRawBolt11Invoice) -> u64 {
803 if o.inner.is_null() { return 0; }
804 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
806 let mut hasher = core::hash::SipHasher::new();
807 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
808 core::hash::Hasher::finish(&hasher)
811 use lightning_invoice::RawBolt11Invoice as nativeRawBolt11InvoiceImport;
812 pub(crate) type nativeRawBolt11Invoice = nativeRawBolt11InvoiceImport;
814 /// Represents an syntactically correct [`Bolt11Invoice`] for a payment on the lightning network,
815 /// but without the signature information.
816 /// Decoding and encoding should not lead to information loss but may lead to different hashes.
818 /// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
821 pub struct RawBolt11Invoice {
822 /// A pointer to the opaque Rust object.
824 /// Nearly everywhere, inner must be non-null, however in places where
825 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
826 pub inner: *mut nativeRawBolt11Invoice,
827 /// Indicates that this is the only struct which contains the same pointer.
829 /// Rust functions which take ownership of an object provided via an argument require
830 /// this to be true and invalidate the object pointed to by inner.
834 impl Drop for RawBolt11Invoice {
836 if self.is_owned && !<*mut nativeRawBolt11Invoice>::is_null(self.inner) {
837 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
841 /// Frees any resources used by the RawBolt11Invoice, if is_owned is set and inner is non-NULL.
843 pub extern "C" fn RawBolt11Invoice_free(this_obj: RawBolt11Invoice) { }
845 /// Used only if an object of this type is returned as a trait impl by a method
846 pub(crate) extern "C" fn RawBolt11Invoice_free_void(this_ptr: *mut c_void) {
847 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawBolt11Invoice) };
850 impl RawBolt11Invoice {
851 pub(crate) fn get_native_ref(&self) -> &'static nativeRawBolt11Invoice {
852 unsafe { &*ObjOps::untweak_ptr(self.inner) }
854 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawBolt11Invoice {
855 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
857 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
858 pub(crate) fn take_inner(mut self) -> *mut nativeRawBolt11Invoice {
859 assert!(self.is_owned);
860 let ret = ObjOps::untweak_ptr(self.inner);
861 self.inner = core::ptr::null_mut();
867 pub extern "C" fn RawBolt11Invoice_get_data(this_ptr: &RawBolt11Invoice) -> crate::lightning_invoice::RawDataPart {
868 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
869 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
873 pub extern "C" fn RawBolt11Invoice_set_data(this_ptr: &mut RawBolt11Invoice, mut val: crate::lightning_invoice::RawDataPart) {
874 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
876 /// Checks if two RawBolt11Invoices contain equal inner contents.
877 /// This ignores pointers and is_owned flags and looks at the values in fields.
878 /// Two objects with NULL inner values will be considered "equal" here.
880 pub extern "C" fn RawBolt11Invoice_eq(a: &RawBolt11Invoice, b: &RawBolt11Invoice) -> bool {
881 if a.inner == b.inner { return true; }
882 if a.inner.is_null() || b.inner.is_null() { return false; }
883 if a.get_native_ref() == b.get_native_ref() { true } else { false }
885 impl Clone for RawBolt11Invoice {
886 fn clone(&self) -> Self {
888 inner: if <*mut nativeRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
889 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
895 /// Used only if an object of this type is returned as a trait impl by a method
896 pub(crate) extern "C" fn RawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
897 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawBolt11Invoice)).clone() })) as *mut c_void
900 /// Creates a copy of the RawBolt11Invoice
901 pub extern "C" fn RawBolt11Invoice_clone(orig: &RawBolt11Invoice) -> RawBolt11Invoice {
904 /// Generates a non-cryptographic 64-bit hash of the RawBolt11Invoice.
906 pub extern "C" fn RawBolt11Invoice_hash(o: &RawBolt11Invoice) -> u64 {
907 if o.inner.is_null() { return 0; }
908 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
910 let mut hasher = core::hash::SipHasher::new();
911 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
912 core::hash::Hasher::finish(&hasher)
915 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
916 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
918 /// Data of the [`RawBolt11Invoice`] that is encoded in the data part
921 pub struct RawDataPart {
922 /// A pointer to the opaque Rust object.
924 /// Nearly everywhere, inner must be non-null, however in places where
925 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
926 pub inner: *mut nativeRawDataPart,
927 /// Indicates that this is the only struct which contains the same pointer.
929 /// Rust functions which take ownership of an object provided via an argument require
930 /// this to be true and invalidate the object pointed to by inner.
934 impl Drop for RawDataPart {
936 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
937 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
941 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
943 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
945 /// Used only if an object of this type is returned as a trait impl by a method
946 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
947 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) };
951 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
952 unsafe { &*ObjOps::untweak_ptr(self.inner) }
954 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
955 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
957 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
958 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
959 assert!(self.is_owned);
960 let ret = ObjOps::untweak_ptr(self.inner);
961 self.inner = core::ptr::null_mut();
965 /// generation time of the invoice
967 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
968 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
969 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
971 /// generation time of the invoice
973 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
974 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
976 /// Checks if two RawDataParts contain equal inner contents.
977 /// This ignores pointers and is_owned flags and looks at the values in fields.
978 /// Two objects with NULL inner values will be considered "equal" here.
980 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
981 if a.inner == b.inner { return true; }
982 if a.inner.is_null() || b.inner.is_null() { return false; }
983 if a.get_native_ref() == b.get_native_ref() { true } else { false }
985 impl Clone for RawDataPart {
986 fn clone(&self) -> Self {
988 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
989 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
995 /// Used only if an object of this type is returned as a trait impl by a method
996 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
997 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRawDataPart)).clone() })) as *mut c_void
1000 /// Creates a copy of the RawDataPart
1001 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
1004 /// Generates a non-cryptographic 64-bit hash of the RawDataPart.
1006 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
1007 if o.inner.is_null() { return 0; }
1008 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1009 #[allow(deprecated)]
1010 let mut hasher = core::hash::SipHasher::new();
1011 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1012 core::hash::Hasher::finish(&hasher)
1015 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1016 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1018 /// A timestamp that refers to a date after 1 January 1970.
1022 /// The Unix timestamp representing the stored time has to be positive and no greater than
1023 /// [`MAX_TIMESTAMP`].
1026 pub struct PositiveTimestamp {
1027 /// A pointer to the opaque Rust object.
1029 /// Nearly everywhere, inner must be non-null, however in places where
1030 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1031 pub inner: *mut nativePositiveTimestamp,
1032 /// Indicates that this is the only struct which contains the same pointer.
1034 /// Rust functions which take ownership of an object provided via an argument require
1035 /// this to be true and invalidate the object pointed to by inner.
1039 impl Drop for PositiveTimestamp {
1040 fn drop(&mut self) {
1041 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1042 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1046 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1048 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1050 /// Used only if an object of this type is returned as a trait impl by a method
1051 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1052 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) };
1055 impl PositiveTimestamp {
1056 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1057 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1059 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1060 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1062 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1063 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1064 assert!(self.is_owned);
1065 let ret = ObjOps::untweak_ptr(self.inner);
1066 self.inner = core::ptr::null_mut();
1070 /// Checks if two PositiveTimestamps contain equal inner contents.
1071 /// This ignores pointers and is_owned flags and looks at the values in fields.
1072 /// Two objects with NULL inner values will be considered "equal" here.
1074 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1075 if a.inner == b.inner { return true; }
1076 if a.inner.is_null() || b.inner.is_null() { return false; }
1077 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1079 impl Clone for PositiveTimestamp {
1080 fn clone(&self) -> Self {
1082 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1083 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1089 /// Used only if an object of this type is returned as a trait impl by a method
1090 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1091 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePositiveTimestamp)).clone() })) as *mut c_void
1094 /// Creates a copy of the PositiveTimestamp
1095 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1098 /// Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
1100 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1101 if o.inner.is_null() { return 0; }
1102 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1103 #[allow(deprecated)]
1104 let mut hasher = core::hash::SipHasher::new();
1105 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1106 core::hash::Hasher::finish(&hasher)
1108 /// SI prefixes for the human readable part
1122 use lightning_invoice::SiPrefix as SiPrefixImport;
1123 pub(crate) type nativeSiPrefix = SiPrefixImport;
1127 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1129 SiPrefix::Milli => nativeSiPrefix::Milli,
1130 SiPrefix::Micro => nativeSiPrefix::Micro,
1131 SiPrefix::Nano => nativeSiPrefix::Nano,
1132 SiPrefix::Pico => nativeSiPrefix::Pico,
1136 pub(crate) fn into_native(self) -> nativeSiPrefix {
1138 SiPrefix::Milli => nativeSiPrefix::Milli,
1139 SiPrefix::Micro => nativeSiPrefix::Micro,
1140 SiPrefix::Nano => nativeSiPrefix::Nano,
1141 SiPrefix::Pico => nativeSiPrefix::Pico,
1145 pub(crate) fn from_native(native: &nativeSiPrefix) -> Self {
1147 nativeSiPrefix::Milli => SiPrefix::Milli,
1148 nativeSiPrefix::Micro => SiPrefix::Micro,
1149 nativeSiPrefix::Nano => SiPrefix::Nano,
1150 nativeSiPrefix::Pico => SiPrefix::Pico,
1154 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1156 nativeSiPrefix::Milli => SiPrefix::Milli,
1157 nativeSiPrefix::Micro => SiPrefix::Micro,
1158 nativeSiPrefix::Nano => SiPrefix::Nano,
1159 nativeSiPrefix::Pico => SiPrefix::Pico,
1163 /// Creates a copy of the SiPrefix
1165 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1169 /// Utility method to constructs a new Milli-variant SiPrefix
1170 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1173 /// Utility method to constructs a new Micro-variant SiPrefix
1174 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1177 /// Utility method to constructs a new Nano-variant SiPrefix
1178 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1181 /// Utility method to constructs a new Pico-variant SiPrefix
1182 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1184 /// Checks if two SiPrefixs contain equal inner contents.
1185 /// This ignores pointers and is_owned flags and looks at the values in fields.
1187 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1188 if &a.to_native() == &b.to_native() { true } else { false }
1190 /// Generates a non-cryptographic 64-bit hash of the SiPrefix.
1192 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1193 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1194 #[allow(deprecated)]
1195 let mut hasher = core::hash::SipHasher::new();
1196 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1197 core::hash::Hasher::finish(&hasher)
1199 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1200 /// This is effectively 10^12 * the prefix multiplier
1203 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1204 let mut ret = this_arg.to_native().multiplier();
1208 /// Enum representing the crypto currencies (or networks) supported by this library
1224 use lightning_invoice::Currency as CurrencyImport;
1225 pub(crate) type nativeCurrency = CurrencyImport;
1229 pub(crate) fn to_native(&self) -> nativeCurrency {
1231 Currency::Bitcoin => nativeCurrency::Bitcoin,
1232 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1233 Currency::Regtest => nativeCurrency::Regtest,
1234 Currency::Simnet => nativeCurrency::Simnet,
1235 Currency::Signet => nativeCurrency::Signet,
1239 pub(crate) fn into_native(self) -> nativeCurrency {
1241 Currency::Bitcoin => nativeCurrency::Bitcoin,
1242 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1243 Currency::Regtest => nativeCurrency::Regtest,
1244 Currency::Simnet => nativeCurrency::Simnet,
1245 Currency::Signet => nativeCurrency::Signet,
1249 pub(crate) fn from_native(native: &nativeCurrency) -> Self {
1251 nativeCurrency::Bitcoin => Currency::Bitcoin,
1252 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1253 nativeCurrency::Regtest => Currency::Regtest,
1254 nativeCurrency::Simnet => Currency::Simnet,
1255 nativeCurrency::Signet => Currency::Signet,
1259 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1261 nativeCurrency::Bitcoin => Currency::Bitcoin,
1262 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1263 nativeCurrency::Regtest => Currency::Regtest,
1264 nativeCurrency::Simnet => Currency::Simnet,
1265 nativeCurrency::Signet => Currency::Signet,
1269 /// Creates a copy of the Currency
1271 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1275 /// Utility method to constructs a new Bitcoin-variant Currency
1276 pub extern "C" fn Currency_bitcoin() -> Currency {
1279 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1280 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1281 Currency::BitcoinTestnet}
1283 /// Utility method to constructs a new Regtest-variant Currency
1284 pub extern "C" fn Currency_regtest() -> Currency {
1287 /// Utility method to constructs a new Simnet-variant Currency
1288 pub extern "C" fn Currency_simnet() -> Currency {
1291 /// Utility method to constructs a new Signet-variant Currency
1292 pub extern "C" fn Currency_signet() -> Currency {
1294 /// Generates a non-cryptographic 64-bit hash of the Currency.
1296 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1297 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1298 #[allow(deprecated)]
1299 let mut hasher = core::hash::SipHasher::new();
1300 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1301 core::hash::Hasher::finish(&hasher)
1303 /// Checks if two Currencys contain equal inner contents.
1304 /// This ignores pointers and is_owned flags and looks at the values in fields.
1306 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1307 if &a.to_native() == &b.to_native() { true } else { false }
1310 use lightning_invoice::Sha256 as nativeSha256Import;
1311 pub(crate) type nativeSha256 = nativeSha256Import;
1317 /// A pointer to the opaque Rust object.
1319 /// Nearly everywhere, inner must be non-null, however in places where
1320 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1321 pub inner: *mut nativeSha256,
1322 /// Indicates that this is the only struct which contains the same pointer.
1324 /// Rust functions which take ownership of an object provided via an argument require
1325 /// this to be true and invalidate the object pointed to by inner.
1329 impl Drop for Sha256 {
1330 fn drop(&mut self) {
1331 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1332 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1336 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1338 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1340 /// Used only if an object of this type is returned as a trait impl by a method
1341 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1342 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) };
1346 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1347 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1349 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1350 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1352 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1353 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1354 assert!(self.is_owned);
1355 let ret = ObjOps::untweak_ptr(self.inner);
1356 self.inner = core::ptr::null_mut();
1360 impl Clone for Sha256 {
1361 fn clone(&self) -> Self {
1363 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1364 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1370 /// Used only if an object of this type is returned as a trait impl by a method
1371 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1372 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeSha256)).clone() })) as *mut c_void
1375 /// Creates a copy of the Sha256
1376 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1379 /// Generates a non-cryptographic 64-bit hash of the Sha256.
1381 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1382 if o.inner.is_null() { return 0; }
1383 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1384 #[allow(deprecated)]
1385 let mut hasher = core::hash::SipHasher::new();
1386 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1387 core::hash::Hasher::finish(&hasher)
1389 /// Checks if two Sha256s contain equal inner contents.
1390 /// This ignores pointers and is_owned flags and looks at the values in fields.
1391 /// Two objects with NULL inner values will be considered "equal" here.
1393 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1394 if a.inner == b.inner { return true; }
1395 if a.inner.is_null() || b.inner.is_null() { return false; }
1396 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1398 /// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
1399 /// single sha256 hash.
1402 pub extern "C" fn Sha256_from_bytes(bytes: *const [u8; 32]) -> crate::lightning_invoice::Sha256 {
1403 let mut ret = lightning_invoice::Sha256::from_bytes(unsafe { &*bytes});
1404 crate::lightning_invoice::Sha256 { inner: ObjOps::heap_alloc(ret), is_owned: true }
1408 use lightning_invoice::Description as nativeDescriptionImport;
1409 pub(crate) type nativeDescription = nativeDescriptionImport;
1411 /// Description string
1414 /// The description can be at most 639 __bytes__ long
1417 pub struct Description {
1418 /// A pointer to the opaque Rust object.
1420 /// Nearly everywhere, inner must be non-null, however in places where
1421 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1422 pub inner: *mut nativeDescription,
1423 /// Indicates that this is the only struct which contains the same pointer.
1425 /// Rust functions which take ownership of an object provided via an argument require
1426 /// this to be true and invalidate the object pointed to by inner.
1430 impl Drop for Description {
1431 fn drop(&mut self) {
1432 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1433 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1437 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1439 pub extern "C" fn Description_free(this_obj: Description) { }
1441 /// Used only if an object of this type is returned as a trait impl by a method
1442 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1443 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) };
1447 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1448 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1450 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1451 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1453 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1454 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1455 assert!(self.is_owned);
1456 let ret = ObjOps::untweak_ptr(self.inner);
1457 self.inner = core::ptr::null_mut();
1461 impl Clone for Description {
1462 fn clone(&self) -> Self {
1464 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1465 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1471 /// Used only if an object of this type is returned as a trait impl by a method
1472 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1473 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDescription)).clone() })) as *mut c_void
1476 /// Creates a copy of the Description
1477 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1480 /// Generates a non-cryptographic 64-bit hash of the Description.
1482 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1483 if o.inner.is_null() { return 0; }
1484 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1485 #[allow(deprecated)]
1486 let mut hasher = core::hash::SipHasher::new();
1487 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1488 core::hash::Hasher::finish(&hasher)
1490 /// Checks if two Descriptions contain equal inner contents.
1491 /// This ignores pointers and is_owned flags and looks at the values in fields.
1492 /// Two objects with NULL inner values will be considered "equal" here.
1494 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1495 if a.inner == b.inner { return true; }
1496 if a.inner.is_null() || b.inner.is_null() { return false; }
1497 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1500 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1501 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1503 /// Payee public key
1506 pub struct PayeePubKey {
1507 /// A pointer to the opaque Rust object.
1509 /// Nearly everywhere, inner must be non-null, however in places where
1510 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1511 pub inner: *mut nativePayeePubKey,
1512 /// Indicates that this is the only struct which contains the same pointer.
1514 /// Rust functions which take ownership of an object provided via an argument require
1515 /// this to be true and invalidate the object pointed to by inner.
1519 impl Drop for PayeePubKey {
1520 fn drop(&mut self) {
1521 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1522 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1526 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1528 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1530 /// Used only if an object of this type is returned as a trait impl by a method
1531 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1532 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) };
1536 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1537 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1539 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1540 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1542 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1543 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1544 assert!(self.is_owned);
1545 let ret = ObjOps::untweak_ptr(self.inner);
1546 self.inner = core::ptr::null_mut();
1551 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1552 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1553 crate::c_types::PublicKey::from_rust(&inner_val)
1556 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1557 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1559 /// Constructs a new PayeePubKey given each field
1562 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1563 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1565 )), is_owned: true }
1567 impl Clone for PayeePubKey {
1568 fn clone(&self) -> Self {
1570 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1571 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1577 /// Used only if an object of this type is returned as a trait impl by a method
1578 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1579 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePayeePubKey)).clone() })) as *mut c_void
1582 /// Creates a copy of the PayeePubKey
1583 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1586 /// Generates a non-cryptographic 64-bit hash of the PayeePubKey.
1588 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1589 if o.inner.is_null() { return 0; }
1590 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1591 #[allow(deprecated)]
1592 let mut hasher = core::hash::SipHasher::new();
1593 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1594 core::hash::Hasher::finish(&hasher)
1596 /// Checks if two PayeePubKeys contain equal inner contents.
1597 /// This ignores pointers and is_owned flags and looks at the values in fields.
1598 /// Two objects with NULL inner values will be considered "equal" here.
1600 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1601 if a.inner == b.inner { return true; }
1602 if a.inner.is_null() || b.inner.is_null() { return false; }
1603 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1606 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1607 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1609 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1613 pub struct ExpiryTime {
1614 /// A pointer to the opaque Rust object.
1616 /// Nearly everywhere, inner must be non-null, however in places where
1617 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1618 pub inner: *mut nativeExpiryTime,
1619 /// Indicates that this is the only struct which contains the same pointer.
1621 /// Rust functions which take ownership of an object provided via an argument require
1622 /// this to be true and invalidate the object pointed to by inner.
1626 impl Drop for ExpiryTime {
1627 fn drop(&mut self) {
1628 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1629 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1633 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1635 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1637 /// Used only if an object of this type is returned as a trait impl by a method
1638 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1639 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) };
1643 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1644 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1646 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1647 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1649 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1650 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1651 assert!(self.is_owned);
1652 let ret = ObjOps::untweak_ptr(self.inner);
1653 self.inner = core::ptr::null_mut();
1657 impl Clone for ExpiryTime {
1658 fn clone(&self) -> Self {
1660 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1661 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1667 /// Used only if an object of this type is returned as a trait impl by a method
1668 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1669 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeExpiryTime)).clone() })) as *mut c_void
1672 /// Creates a copy of the ExpiryTime
1673 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1676 /// Generates a non-cryptographic 64-bit hash of the ExpiryTime.
1678 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1679 if o.inner.is_null() { return 0; }
1680 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1681 #[allow(deprecated)]
1682 let mut hasher = core::hash::SipHasher::new();
1683 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1684 core::hash::Hasher::finish(&hasher)
1686 /// Checks if two ExpiryTimes contain equal inner contents.
1687 /// This ignores pointers and is_owned flags and looks at the values in fields.
1688 /// Two objects with NULL inner values will be considered "equal" here.
1690 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1691 if a.inner == b.inner { return true; }
1692 if a.inner.is_null() || b.inner.is_null() { return false; }
1693 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1696 use lightning_invoice::MinFinalCltvExpiryDelta as nativeMinFinalCltvExpiryDeltaImport;
1697 pub(crate) type nativeMinFinalCltvExpiryDelta = nativeMinFinalCltvExpiryDeltaImport;
1699 /// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
1702 pub struct MinFinalCltvExpiryDelta {
1703 /// A pointer to the opaque Rust object.
1705 /// Nearly everywhere, inner must be non-null, however in places where
1706 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1707 pub inner: *mut nativeMinFinalCltvExpiryDelta,
1708 /// Indicates that this is the only struct which contains the same pointer.
1710 /// Rust functions which take ownership of an object provided via an argument require
1711 /// this to be true and invalidate the object pointed to by inner.
1715 impl Drop for MinFinalCltvExpiryDelta {
1716 fn drop(&mut self) {
1717 if self.is_owned && !<*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) {
1718 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1722 /// Frees any resources used by the MinFinalCltvExpiryDelta, if is_owned is set and inner is non-NULL.
1724 pub extern "C" fn MinFinalCltvExpiryDelta_free(this_obj: MinFinalCltvExpiryDelta) { }
1726 /// Used only if an object of this type is returned as a trait impl by a method
1727 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_free_void(this_ptr: *mut c_void) {
1728 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiryDelta) };
1731 impl MinFinalCltvExpiryDelta {
1732 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiryDelta {
1733 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1735 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiryDelta {
1736 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1738 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1739 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiryDelta {
1740 assert!(self.is_owned);
1741 let ret = ObjOps::untweak_ptr(self.inner);
1742 self.inner = core::ptr::null_mut();
1747 pub extern "C" fn MinFinalCltvExpiryDelta_get_a(this_ptr: &MinFinalCltvExpiryDelta) -> u64 {
1748 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1752 pub extern "C" fn MinFinalCltvExpiryDelta_set_a(this_ptr: &mut MinFinalCltvExpiryDelta, mut val: u64) {
1753 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1755 /// Constructs a new MinFinalCltvExpiryDelta given each field
1758 pub extern "C" fn MinFinalCltvExpiryDelta_new(mut a_arg: u64) -> MinFinalCltvExpiryDelta {
1759 MinFinalCltvExpiryDelta { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiryDelta (
1761 )), is_owned: true }
1763 impl Clone for MinFinalCltvExpiryDelta {
1764 fn clone(&self) -> Self {
1766 inner: if <*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) { core::ptr::null_mut() } else {
1767 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1773 /// Used only if an object of this type is returned as a trait impl by a method
1774 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_clone_void(this_ptr: *const c_void) -> *mut c_void {
1775 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void
1778 /// Creates a copy of the MinFinalCltvExpiryDelta
1779 pub extern "C" fn MinFinalCltvExpiryDelta_clone(orig: &MinFinalCltvExpiryDelta) -> MinFinalCltvExpiryDelta {
1782 /// Generates a non-cryptographic 64-bit hash of the MinFinalCltvExpiryDelta.
1784 pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 {
1785 if o.inner.is_null() { return 0; }
1786 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1787 #[allow(deprecated)]
1788 let mut hasher = core::hash::SipHasher::new();
1789 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1790 core::hash::Hasher::finish(&hasher)
1792 /// Checks if two MinFinalCltvExpiryDeltas contain equal inner contents.
1793 /// This ignores pointers and is_owned flags and looks at the values in fields.
1794 /// Two objects with NULL inner values will be considered "equal" here.
1796 pub extern "C" fn MinFinalCltvExpiryDelta_eq(a: &MinFinalCltvExpiryDelta, b: &MinFinalCltvExpiryDelta) -> bool {
1797 if a.inner == b.inner { return true; }
1798 if a.inner.is_null() || b.inner.is_null() { return false; }
1799 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1801 /// Fallback address in case no LN payment is possible
1807 version: crate::c_types::WitnessVersion,
1808 program: crate::c_types::derived::CVec_u8Z,
1811 crate::c_types::TwentyBytes),
1813 crate::c_types::TwentyBytes),
1815 use lightning_invoice::Fallback as FallbackImport;
1816 pub(crate) type nativeFallback = FallbackImport;
1820 pub(crate) fn to_native(&self) -> nativeFallback {
1822 Fallback::SegWitProgram {ref version, ref program, } => {
1823 let mut version_nonref = Clone::clone(version);
1824 let mut program_nonref = Clone::clone(program);
1825 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1826 nativeFallback::SegWitProgram {
1827 version: version_nonref.into(),
1828 program: local_program_nonref,
1831 Fallback::PubKeyHash (ref a, ) => {
1832 let mut a_nonref = Clone::clone(a);
1833 nativeFallback::PubKeyHash (
1834 bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
1837 Fallback::ScriptHash (ref a, ) => {
1838 let mut a_nonref = Clone::clone(a);
1839 nativeFallback::ScriptHash (
1840 bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a_nonref.data)),
1846 pub(crate) fn into_native(self) -> nativeFallback {
1848 Fallback::SegWitProgram {mut version, mut program, } => {
1849 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1850 nativeFallback::SegWitProgram {
1851 version: version.into(),
1852 program: local_program,
1855 Fallback::PubKeyHash (mut a, ) => {
1856 nativeFallback::PubKeyHash (
1857 bitcoin::hash_types::PubkeyHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
1860 Fallback::ScriptHash (mut a, ) => {
1861 nativeFallback::ScriptHash (
1862 bitcoin::hash_types::ScriptHash::from_hash(bitcoin::hashes::Hash::from_inner(a.data)),
1868 pub(crate) fn from_native(native: &nativeFallback) -> Self {
1870 nativeFallback::SegWitProgram {ref version, ref program, } => {
1871 let mut version_nonref = Clone::clone(version);
1872 let mut program_nonref = Clone::clone(program);
1873 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1874 Fallback::SegWitProgram {
1875 version: version_nonref.into(),
1876 program: local_program_nonref.into(),
1879 nativeFallback::PubKeyHash (ref a, ) => {
1880 let mut a_nonref = Clone::clone(a);
1881 Fallback::PubKeyHash (
1882 crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
1885 nativeFallback::ScriptHash (ref a, ) => {
1886 let mut a_nonref = Clone::clone(a);
1887 Fallback::ScriptHash (
1888 crate::c_types::TwentyBytes { data: a_nonref.as_hash().into_inner() },
1894 pub(crate) fn native_into(native: nativeFallback) -> Self {
1896 nativeFallback::SegWitProgram {mut version, mut program, } => {
1897 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1898 Fallback::SegWitProgram {
1899 version: version.into(),
1900 program: local_program.into(),
1903 nativeFallback::PubKeyHash (mut a, ) => {
1904 Fallback::PubKeyHash (
1905 crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
1908 nativeFallback::ScriptHash (mut a, ) => {
1909 Fallback::ScriptHash (
1910 crate::c_types::TwentyBytes { data: a.as_hash().into_inner() },
1916 /// Frees any resources used by the Fallback
1918 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1919 /// Creates a copy of the Fallback
1921 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
1925 /// Utility method to constructs a new SegWitProgram-variant Fallback
1926 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
1927 Fallback::SegWitProgram {
1933 /// Utility method to constructs a new PubKeyHash-variant Fallback
1934 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1935 Fallback::PubKeyHash(a, )
1938 /// Utility method to constructs a new ScriptHash-variant Fallback
1939 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
1940 Fallback::ScriptHash(a, )
1942 /// Generates a non-cryptographic 64-bit hash of the Fallback.
1944 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
1945 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1946 #[allow(deprecated)]
1947 let mut hasher = core::hash::SipHasher::new();
1948 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1949 core::hash::Hasher::finish(&hasher)
1951 /// Checks if two Fallbacks contain equal inner contents.
1952 /// This ignores pointers and is_owned flags and looks at the values in fields.
1954 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
1955 if &a.to_native() == &b.to_native() { true } else { false }
1958 use lightning_invoice::Bolt11InvoiceSignature as nativeBolt11InvoiceSignatureImport;
1959 pub(crate) type nativeBolt11InvoiceSignature = nativeBolt11InvoiceSignatureImport;
1961 /// Recoverable signature
1964 pub struct Bolt11InvoiceSignature {
1965 /// A pointer to the opaque Rust object.
1967 /// Nearly everywhere, inner must be non-null, however in places where
1968 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1969 pub inner: *mut nativeBolt11InvoiceSignature,
1970 /// Indicates that this is the only struct which contains the same pointer.
1972 /// Rust functions which take ownership of an object provided via an argument require
1973 /// this to be true and invalidate the object pointed to by inner.
1977 impl Drop for Bolt11InvoiceSignature {
1978 fn drop(&mut self) {
1979 if self.is_owned && !<*mut nativeBolt11InvoiceSignature>::is_null(self.inner) {
1980 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1984 /// Frees any resources used by the Bolt11InvoiceSignature, if is_owned is set and inner is non-NULL.
1986 pub extern "C" fn Bolt11InvoiceSignature_free(this_obj: Bolt11InvoiceSignature) { }
1988 /// Used only if an object of this type is returned as a trait impl by a method
1989 pub(crate) extern "C" fn Bolt11InvoiceSignature_free_void(this_ptr: *mut c_void) {
1990 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11InvoiceSignature) };
1993 impl Bolt11InvoiceSignature {
1994 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11InvoiceSignature {
1995 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1997 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11InvoiceSignature {
1998 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2000 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2001 pub(crate) fn take_inner(mut self) -> *mut nativeBolt11InvoiceSignature {
2002 assert!(self.is_owned);
2003 let ret = ObjOps::untweak_ptr(self.inner);
2004 self.inner = core::ptr::null_mut();
2008 impl Clone for Bolt11InvoiceSignature {
2009 fn clone(&self) -> Self {
2011 inner: if <*mut nativeBolt11InvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
2012 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2018 /// Used only if an object of this type is returned as a trait impl by a method
2019 pub(crate) extern "C" fn Bolt11InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
2020 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeBolt11InvoiceSignature)).clone() })) as *mut c_void
2023 /// Creates a copy of the Bolt11InvoiceSignature
2024 pub extern "C" fn Bolt11InvoiceSignature_clone(orig: &Bolt11InvoiceSignature) -> Bolt11InvoiceSignature {
2027 /// Generates a non-cryptographic 64-bit hash of the Bolt11InvoiceSignature.
2029 pub extern "C" fn Bolt11InvoiceSignature_hash(o: &Bolt11InvoiceSignature) -> u64 {
2030 if o.inner.is_null() { return 0; }
2031 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2032 #[allow(deprecated)]
2033 let mut hasher = core::hash::SipHasher::new();
2034 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2035 core::hash::Hasher::finish(&hasher)
2037 /// Checks if two Bolt11InvoiceSignatures contain equal inner contents.
2038 /// This ignores pointers and is_owned flags and looks at the values in fields.
2039 /// Two objects with NULL inner values will be considered "equal" here.
2041 pub extern "C" fn Bolt11InvoiceSignature_eq(a: &Bolt11InvoiceSignature, b: &Bolt11InvoiceSignature) -> bool {
2042 if a.inner == b.inner { return true; }
2043 if a.inner.is_null() || b.inner.is_null() { return false; }
2044 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2047 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2048 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2050 /// Private routing information
2053 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2057 pub struct PrivateRoute {
2058 /// A pointer to the opaque Rust object.
2060 /// Nearly everywhere, inner must be non-null, however in places where
2061 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2062 pub inner: *mut nativePrivateRoute,
2063 /// Indicates that this is the only struct which contains the same pointer.
2065 /// Rust functions which take ownership of an object provided via an argument require
2066 /// this to be true and invalidate the object pointed to by inner.
2070 impl Drop for PrivateRoute {
2071 fn drop(&mut self) {
2072 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2073 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2077 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2079 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2081 /// Used only if an object of this type is returned as a trait impl by a method
2082 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2083 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) };
2087 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2088 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2090 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2091 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2093 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2094 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2095 assert!(self.is_owned);
2096 let ret = ObjOps::untweak_ptr(self.inner);
2097 self.inner = core::ptr::null_mut();
2101 impl Clone for PrivateRoute {
2102 fn clone(&self) -> Self {
2104 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2105 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2111 /// Used only if an object of this type is returned as a trait impl by a method
2112 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2113 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePrivateRoute)).clone() })) as *mut c_void
2116 /// Creates a copy of the PrivateRoute
2117 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2120 /// Generates a non-cryptographic 64-bit hash of the PrivateRoute.
2122 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2123 if o.inner.is_null() { return 0; }
2124 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2125 #[allow(deprecated)]
2126 let mut hasher = core::hash::SipHasher::new();
2127 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2128 core::hash::Hasher::finish(&hasher)
2130 /// Checks if two PrivateRoutes contain equal inner contents.
2131 /// This ignores pointers and is_owned flags and looks at the values in fields.
2132 /// Two objects with NULL inner values will be considered "equal" here.
2134 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2135 if a.inner == b.inner { return true; }
2136 if a.inner.is_null() || b.inner.is_null() { return false; }
2137 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2139 /// Disassembles the `SignedRawBolt11Invoice` into its three parts:
2141 /// 2. hash of the raw invoice
2145 pub extern "C" fn SignedRawBolt11Invoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::C3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ {
2146 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2147 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();
2151 /// The [`RawBolt11Invoice`] which was signed.
2154 pub extern "C" fn SignedRawBolt11Invoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::RawBolt11Invoice {
2155 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2156 crate::lightning_invoice::RawBolt11Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawBolt11Invoice<>) as *mut _) }, is_owned: false }
2159 /// The hash of the [`RawBolt11Invoice`] that was signed.
2162 pub extern "C" fn SignedRawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> *const [u8; 32] {
2163 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2167 /// Signature for the invoice.
2170 pub extern "C" fn SignedRawBolt11Invoice_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::Bolt11InvoiceSignature {
2171 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2172 crate::lightning_invoice::Bolt11InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::Bolt11InvoiceSignature<>) as *mut _) }, is_owned: false }
2175 /// Recovers the public key used for signing the invoice from the recoverable signature.
2178 pub extern "C" fn SignedRawBolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_PayeePubKeySecp256k1ErrorZ {
2179 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2180 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() };
2184 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2185 /// valid for the recovered signature (which should always be true?).
2188 pub extern "C" fn SignedRawBolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> bool {
2189 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2193 /// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
2196 pub extern "C" fn RawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
2197 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2198 crate::c_types::ThirtyTwoBytes { data: ret }
2202 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2205 pub extern "C" fn RawBolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Sha256 {
2206 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2207 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 };
2212 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2215 pub extern "C" fn RawBolt11Invoice_description(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Description {
2216 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2217 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 };
2222 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2225 pub extern "C" fn RawBolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::PayeePubKey {
2226 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2227 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 };
2232 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2235 pub extern "C" fn RawBolt11Invoice_description_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Sha256 {
2236 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2237 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 };
2242 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2245 pub extern "C" fn RawBolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::ExpiryTime {
2246 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2247 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 };
2252 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2255 pub extern "C" fn RawBolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::MinFinalCltvExpiryDelta {
2256 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2257 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 };
2263 pub extern "C" fn RawBolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
2264 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2265 let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*ret.as_ref().unwrap()).clone().0 } }) };
2271 pub extern "C" fn RawBolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2272 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2273 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() }) };
2278 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2281 pub extern "C" fn RawBolt11Invoice_features(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
2282 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2283 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 };
2289 pub extern "C" fn RawBolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2290 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2291 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 } }); };
2297 pub extern "C" fn RawBolt11Invoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2298 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2299 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() }) };
2305 pub extern "C" fn RawBolt11Invoice_currency(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Currency {
2306 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2307 crate::lightning_invoice::Currency::native_into(ret)
2310 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2312 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2315 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2316 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2317 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() };
2321 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2322 /// the range `0..=MAX_TIMESTAMP`.
2324 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2326 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2329 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2330 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2331 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() };
2335 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2336 /// `0..=MAX_TIMESTAMP`.
2338 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2340 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2343 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2344 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2345 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() };
2349 /// Returns the Unix timestamp representing the stored time
2352 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2353 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2357 /// Returns the duration of the stored time since the Unix epoch
2360 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2361 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2365 /// Returns the [`SystemTime`] representing the stored time
2368 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2369 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2370 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2373 /// The hash of the [`RawBolt11Invoice`] that was signed.
2376 pub extern "C" fn Bolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
2377 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2378 crate::c_types::ThirtyTwoBytes { data: ret }
2381 /// Transform the `Bolt11Invoice` into its unchecked version.
2384 pub extern "C" fn Bolt11Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::SignedRawBolt11Invoice {
2385 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2386 crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2389 /// Check that the invoice is signed correctly and that key recovery works
2392 pub extern "C" fn Bolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CResult_NoneBolt11SemanticErrorZ {
2393 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2394 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() };
2398 /// Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
2400 /// use lightning_invoice::*;
2402 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2403 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2404 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2405 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2406 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2407 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2408 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2409 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2410 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2411 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2412 /// j5r6drg6k6zcqj0fcwg\";
2414 /// let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
2416 /// assert!(Bolt11Invoice::from_signed(signed).is_ok());
2420 pub extern "C" fn Bolt11Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_Bolt11InvoiceBolt11SemanticErrorZ {
2421 let mut ret = lightning_invoice::Bolt11Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2422 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() };
2426 /// Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
2429 pub extern "C" fn Bolt11Invoice_timestamp(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2430 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2431 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2434 /// Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
2437 pub extern "C" fn Bolt11Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2438 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2442 /// Returns the hash to which we will receive the preimage on completion of the payment
2445 pub extern "C" fn Bolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
2446 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2450 /// Get the payee's public key if one was included in the invoice
2452 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2455 pub extern "C" fn Bolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2456 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2457 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2461 /// Get the payment secret if one was included in the invoice
2464 pub extern "C" fn Bolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
2465 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2469 /// Get the payment metadata blob if one was included in the invoice
2472 pub extern "C" fn Bolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2473 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2474 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() }) };
2478 /// Get the invoice features if they were included in the invoice
2480 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2483 pub extern "C" fn Bolt11Invoice_features(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
2484 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2485 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 };
2489 /// Recover the payee's public key (only to be used if none was included in the invoice)
2492 pub extern "C" fn Bolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2493 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2494 crate::c_types::PublicKey::from_rust(&ret)
2497 /// Returns the Duration since the Unix epoch at which the invoice expires.
2498 /// Returning None if overflow occurred.
2501 pub extern "C" fn Bolt11Invoice_expires_at(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2502 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expires_at();
2503 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().as_secs() }) };
2507 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2510 pub extern "C" fn Bolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2511 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2515 /// Returns whether the invoice has expired.
2518 pub extern "C" fn Bolt11Invoice_is_expired(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> bool {
2519 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2523 /// Returns the Duration remaining until the invoice expires.
2526 pub extern "C" fn Bolt11Invoice_duration_until_expiry(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2527 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_until_expiry();
2531 /// Returns the Duration remaining until the invoice expires given the current time.
2532 /// `time` is the timestamp as a duration since the Unix epoch.
2535 pub extern "C" fn Bolt11Invoice_expiration_remaining_from_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut time: u64) -> u64 {
2536 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiration_remaining_from_epoch(core::time::Duration::from_secs(time));
2540 /// Returns whether the expiry time would pass at the given point in time.
2541 /// `at_time` is the timestamp as a duration since the Unix epoch.
2544 pub extern "C" fn Bolt11Invoice_would_expire(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut at_time: u64) -> bool {
2545 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2549 /// Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
2550 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
2553 pub extern "C" fn Bolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2554 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2558 /// Returns a list of all fallback addresses as [`Address`]es
2561 pub extern "C" fn Bolt11Invoice_fallback_addresses(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_StrZ {
2562 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fallback_addresses();
2563 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { alloc::string::ToString::to_string(&item).into() }); };
2567 /// Returns a list of all routes included in the invoice
2570 pub extern "C" fn Bolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2571 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2572 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 } }); };
2576 /// Returns a list of all routes included in the invoice as the underlying hints
2579 pub extern "C" fn Bolt11Invoice_route_hints(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2580 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2581 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 } }); };
2585 /// Returns the currency for which the invoice was issued
2588 pub extern "C" fn Bolt11Invoice_currency(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::Currency {
2589 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2590 crate::lightning_invoice::Currency::native_into(ret)
2593 /// Returns the amount if specified in the invoice as millisatoshis.
2596 pub extern "C" fn Bolt11Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2597 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2598 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() }) };
2602 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2603 /// returns [`CreationError::DescriptionTooLong`] otherwise
2605 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2608 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2609 let mut ret = lightning_invoice::Description::new(description.into_string());
2610 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() };
2614 /// Returns the underlying description [`String`]
2617 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::c_types::Str {
2618 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2622 /// Construct an `ExpiryTime` from seconds.
2625 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2626 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2627 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2630 /// Construct an `ExpiryTime` from a [`Duration`], dropping the sub-second part.
2633 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2634 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2635 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2638 /// Returns the expiry time in seconds
2641 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2642 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2646 /// Returns a reference to the underlying [`Duration`] (=expiry time)
2649 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2650 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2654 /// Creates a new (partial) route from a list of hops
2657 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2658 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2659 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() };
2663 /// Returns the underlying list of hops
2666 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2667 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2668 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2671 /// Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`]
2675 pub enum CreationError {
2676 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
2678 /// The specified route has too many hops and can't be encoded
2680 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2681 TimestampOutOfBounds,
2682 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2684 /// Route hints were required for this invoice and were missing. Applies to
2685 /// [phantom invoices].
2687 /// [phantom invoices]: crate::utils::create_phantom_invoice
2689 /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
2691 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
2692 MinFinalCltvExpiryDeltaTooShort,
2694 use lightning_invoice::CreationError as CreationErrorImport;
2695 pub(crate) type nativeCreationError = CreationErrorImport;
2697 impl CreationError {
2699 pub(crate) fn to_native(&self) -> nativeCreationError {
2701 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2702 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2703 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2704 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2705 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2706 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2710 pub(crate) fn into_native(self) -> nativeCreationError {
2712 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2713 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2714 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2715 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2716 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2717 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2721 pub(crate) fn from_native(native: &nativeCreationError) -> Self {
2723 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2724 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2725 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2726 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2727 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2728 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2732 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2734 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2735 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2736 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2737 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2738 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2739 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2743 /// Creates a copy of the CreationError
2745 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2749 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2750 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2751 CreationError::DescriptionTooLong}
2753 /// Utility method to constructs a new RouteTooLong-variant CreationError
2754 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2755 CreationError::RouteTooLong}
2757 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2758 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2759 CreationError::TimestampOutOfBounds}
2761 /// Utility method to constructs a new InvalidAmount-variant CreationError
2762 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2763 CreationError::InvalidAmount}
2765 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2766 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2767 CreationError::MissingRouteHints}
2769 /// Utility method to constructs a new MinFinalCltvExpiryDeltaTooShort-variant CreationError
2770 pub extern "C" fn CreationError_min_final_cltv_expiry_delta_too_short() -> CreationError {
2771 CreationError::MinFinalCltvExpiryDeltaTooShort}
2772 /// Checks if two CreationErrors contain equal inner contents.
2773 /// This ignores pointers and is_owned flags and looks at the values in fields.
2775 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2776 if &a.to_native() == &b.to_native() { true } else { false }
2779 /// Get the string representation of a CreationError object
2780 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2781 alloc::format!("{}", &o.to_native()).into()
2783 /// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
2784 /// the requirements sections in BOLT #11
2788 pub enum Bolt11SemanticError {
2789 /// The invoice is missing the mandatory payment hash
2791 /// The invoice has multiple payment hashes which isn't allowed
2792 MultiplePaymentHashes,
2793 /// No description or description hash are part of the invoice
2795 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2796 MultipleDescriptions,
2797 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2800 /// The invoice contains multiple payment secrets
2801 MultiplePaymentSecrets,
2802 /// The invoice's features are invalid
2804 /// The recovery id doesn't fit the signature/pub key
2806 /// The invoice's signature is invalid
2808 /// The invoice's amount was not a whole number of millisatoshis
2811 use lightning_invoice::Bolt11SemanticError as Bolt11SemanticErrorImport;
2812 pub(crate) type nativeBolt11SemanticError = Bolt11SemanticErrorImport;
2814 impl Bolt11SemanticError {
2816 pub(crate) fn to_native(&self) -> nativeBolt11SemanticError {
2818 Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
2819 Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
2820 Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
2821 Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
2822 Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
2823 Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
2824 Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
2825 Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
2826 Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
2827 Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
2831 pub(crate) fn into_native(self) -> nativeBolt11SemanticError {
2833 Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
2834 Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
2835 Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
2836 Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
2837 Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
2838 Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
2839 Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
2840 Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
2841 Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
2842 Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
2846 pub(crate) fn from_native(native: &nativeBolt11SemanticError) -> Self {
2848 nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
2849 nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
2850 nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
2851 nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
2852 nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
2853 nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
2854 nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
2855 nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
2856 nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
2857 nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
2861 pub(crate) fn native_into(native: nativeBolt11SemanticError) -> Self {
2863 nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
2864 nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
2865 nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
2866 nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
2867 nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
2868 nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
2869 nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
2870 nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
2871 nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
2872 nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
2876 /// Creates a copy of the Bolt11SemanticError
2878 pub extern "C" fn Bolt11SemanticError_clone(orig: &Bolt11SemanticError) -> Bolt11SemanticError {
2882 /// Utility method to constructs a new NoPaymentHash-variant Bolt11SemanticError
2883 pub extern "C" fn Bolt11SemanticError_no_payment_hash() -> Bolt11SemanticError {
2884 Bolt11SemanticError::NoPaymentHash}
2886 /// Utility method to constructs a new MultiplePaymentHashes-variant Bolt11SemanticError
2887 pub extern "C" fn Bolt11SemanticError_multiple_payment_hashes() -> Bolt11SemanticError {
2888 Bolt11SemanticError::MultiplePaymentHashes}
2890 /// Utility method to constructs a new NoDescription-variant Bolt11SemanticError
2891 pub extern "C" fn Bolt11SemanticError_no_description() -> Bolt11SemanticError {
2892 Bolt11SemanticError::NoDescription}
2894 /// Utility method to constructs a new MultipleDescriptions-variant Bolt11SemanticError
2895 pub extern "C" fn Bolt11SemanticError_multiple_descriptions() -> Bolt11SemanticError {
2896 Bolt11SemanticError::MultipleDescriptions}
2898 /// Utility method to constructs a new NoPaymentSecret-variant Bolt11SemanticError
2899 pub extern "C" fn Bolt11SemanticError_no_payment_secret() -> Bolt11SemanticError {
2900 Bolt11SemanticError::NoPaymentSecret}
2902 /// Utility method to constructs a new MultiplePaymentSecrets-variant Bolt11SemanticError
2903 pub extern "C" fn Bolt11SemanticError_multiple_payment_secrets() -> Bolt11SemanticError {
2904 Bolt11SemanticError::MultiplePaymentSecrets}
2906 /// Utility method to constructs a new InvalidFeatures-variant Bolt11SemanticError
2907 pub extern "C" fn Bolt11SemanticError_invalid_features() -> Bolt11SemanticError {
2908 Bolt11SemanticError::InvalidFeatures}
2910 /// Utility method to constructs a new InvalidRecoveryId-variant Bolt11SemanticError
2911 pub extern "C" fn Bolt11SemanticError_invalid_recovery_id() -> Bolt11SemanticError {
2912 Bolt11SemanticError::InvalidRecoveryId}
2914 /// Utility method to constructs a new InvalidSignature-variant Bolt11SemanticError
2915 pub extern "C" fn Bolt11SemanticError_invalid_signature() -> Bolt11SemanticError {
2916 Bolt11SemanticError::InvalidSignature}
2918 /// Utility method to constructs a new ImpreciseAmount-variant Bolt11SemanticError
2919 pub extern "C" fn Bolt11SemanticError_imprecise_amount() -> Bolt11SemanticError {
2920 Bolt11SemanticError::ImpreciseAmount}
2921 /// Checks if two Bolt11SemanticErrors contain equal inner contents.
2922 /// This ignores pointers and is_owned flags and looks at the values in fields.
2924 pub extern "C" fn Bolt11SemanticError_eq(a: &Bolt11SemanticError, b: &Bolt11SemanticError) -> bool {
2925 if &a.to_native() == &b.to_native() { true } else { false }
2928 /// Get the string representation of a Bolt11SemanticError object
2929 pub extern "C" fn Bolt11SemanticError_to_str(o: &crate::lightning_invoice::Bolt11SemanticError) -> Str {
2930 alloc::format!("{}", &o.to_native()).into()
2932 /// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
2937 pub enum SignOrCreationError {
2938 /// An error occurred during signing
2940 /// An error occurred while building the transaction
2942 crate::lightning_invoice::CreationError),
2944 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
2945 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
2947 impl SignOrCreationError {
2949 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
2951 SignOrCreationError::SignError => {
2952 nativeSignOrCreationError::SignError (
2956 SignOrCreationError::CreationError (ref a, ) => {
2957 let mut a_nonref = Clone::clone(a);
2958 nativeSignOrCreationError::CreationError (
2959 a_nonref.into_native(),
2965 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
2967 SignOrCreationError::SignError => {
2968 nativeSignOrCreationError::SignError (
2972 SignOrCreationError::CreationError (mut a, ) => {
2973 nativeSignOrCreationError::CreationError (
2980 pub(crate) fn from_native(native: &nativeSignOrCreationError) -> Self {
2982 nativeSignOrCreationError::SignError (ref a, ) => {
2983 SignOrCreationError::SignError },
2984 nativeSignOrCreationError::CreationError (ref a, ) => {
2985 let mut a_nonref = Clone::clone(a);
2986 SignOrCreationError::CreationError (
2987 crate::lightning_invoice::CreationError::native_into(a_nonref),
2993 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
2995 nativeSignOrCreationError::SignError (mut a, ) => {
2996 SignOrCreationError::SignError },
2997 nativeSignOrCreationError::CreationError (mut a, ) => {
2998 SignOrCreationError::CreationError (
2999 crate::lightning_invoice::CreationError::native_into(a),
3005 /// Frees any resources used by the SignOrCreationError
3007 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
3008 /// Creates a copy of the SignOrCreationError
3010 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
3014 /// Utility method to constructs a new SignError-variant SignOrCreationError
3015 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
3016 SignOrCreationError::SignError
3019 /// Utility method to constructs a new CreationError-variant SignOrCreationError
3020 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
3021 SignOrCreationError::CreationError(a, )
3023 /// Checks if two SignOrCreationErrors contain equal inner contents.
3024 /// This ignores pointers and is_owned flags and looks at the values in fields.
3026 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
3027 if &a.to_native() == &b.to_native() { true } else { false }
3030 /// Get the string representation of a SignOrCreationError object
3031 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
3032 alloc::format!("{}", &o.to_native()).into()