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};
170 /// Errors that indicate what is wrong with the invoice. They have some granularity for debug
171 /// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
175 pub enum Bolt11ParseError {
177 crate::c_types::Bech32Error),
179 crate::c_types::Error),
181 crate::c_types::Secp256k1Error),
187 UnexpectedEndOfTaggedFields,
188 DescriptionDecodeError(
189 crate::c_types::Error),
191 IntegerOverflowError,
192 InvalidSegWitProgramLength,
193 InvalidPubKeyHashLength,
194 InvalidScriptHashLength,
197 crate::c_types::Str),
198 /// Not an error, but used internally to signal that a part of the invoice should be ignored
199 /// according to BOLT11
202 use lightning_invoice::Bolt11ParseError as Bolt11ParseErrorImport;
203 pub(crate) type nativeBolt11ParseError = Bolt11ParseErrorImport;
205 impl Bolt11ParseError {
207 pub(crate) fn to_native(&self) -> nativeBolt11ParseError {
209 Bolt11ParseError::Bech32Error (ref a, ) => {
210 let mut a_nonref = Clone::clone(a);
211 nativeBolt11ParseError::Bech32Error (
212 a_nonref.into_rust(),
215 Bolt11ParseError::ParseAmountError (ref a, ) => {
216 let mut a_nonref = Clone::clone(a);
217 nativeBolt11ParseError::ParseAmountError (
218 u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
221 Bolt11ParseError::MalformedSignature (ref a, ) => {
222 let mut a_nonref = Clone::clone(a);
223 nativeBolt11ParseError::MalformedSignature (
224 a_nonref.into_rust(),
227 Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
228 Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
229 Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
230 Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
231 Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
232 Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
233 Bolt11ParseError::DescriptionDecodeError (ref a, ) => {
234 let mut a_nonref = Clone::clone(a);
235 nativeBolt11ParseError::DescriptionDecodeError (
236 core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
239 Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
240 Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
241 Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
242 Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
243 Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
244 Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
245 Bolt11ParseError::InvalidSliceLength (ref a, ) => {
246 let mut a_nonref = Clone::clone(a);
247 nativeBolt11ParseError::InvalidSliceLength (
248 a_nonref.into_string(),
251 Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
255 pub(crate) fn into_native(self) -> nativeBolt11ParseError {
257 Bolt11ParseError::Bech32Error (mut a, ) => {
258 nativeBolt11ParseError::Bech32Error (
262 Bolt11ParseError::ParseAmountError (mut a, ) => {
263 nativeBolt11ParseError::ParseAmountError (
264 u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
267 Bolt11ParseError::MalformedSignature (mut a, ) => {
268 nativeBolt11ParseError::MalformedSignature (
272 Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
273 Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
274 Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
275 Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
276 Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
277 Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
278 Bolt11ParseError::DescriptionDecodeError (mut a, ) => {
279 nativeBolt11ParseError::DescriptionDecodeError (
280 core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
283 Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
284 Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
285 Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
286 Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
287 Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
288 Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
289 Bolt11ParseError::InvalidSliceLength (mut a, ) => {
290 nativeBolt11ParseError::InvalidSliceLength (
294 Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
298 pub(crate) fn from_native(native: &Bolt11ParseErrorImport) -> Self {
299 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBolt11ParseError) };
301 nativeBolt11ParseError::Bech32Error (ref a, ) => {
302 let mut a_nonref = Clone::clone(a);
303 Bolt11ParseError::Bech32Error (
304 crate::c_types::Bech32Error::from_rust(a_nonref),
307 nativeBolt11ParseError::ParseAmountError (ref a, ) => {
308 let mut a_nonref = Clone::clone(a);
309 Bolt11ParseError::ParseAmountError (
310 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
313 nativeBolt11ParseError::MalformedSignature (ref a, ) => {
314 let mut a_nonref = Clone::clone(a);
315 Bolt11ParseError::MalformedSignature (
316 crate::c_types::Secp256k1Error::from_rust(a_nonref),
319 nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
320 nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
321 nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
322 nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
323 nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
324 nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
325 nativeBolt11ParseError::DescriptionDecodeError (ref a, ) => {
326 let mut a_nonref = Clone::clone(a);
327 Bolt11ParseError::DescriptionDecodeError (
328 crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
331 nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
332 nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
333 nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
334 nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
335 nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
336 nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
337 nativeBolt11ParseError::InvalidSliceLength (ref a, ) => {
338 let mut a_nonref = Clone::clone(a);
339 Bolt11ParseError::InvalidSliceLength (
343 nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
347 pub(crate) fn native_into(native: nativeBolt11ParseError) -> Self {
349 nativeBolt11ParseError::Bech32Error (mut a, ) => {
350 Bolt11ParseError::Bech32Error (
351 crate::c_types::Bech32Error::from_rust(a),
354 nativeBolt11ParseError::ParseAmountError (mut a, ) => {
355 Bolt11ParseError::ParseAmountError (
356 crate::c_types::Error { _dummy: 0 } /*a*/,
359 nativeBolt11ParseError::MalformedSignature (mut a, ) => {
360 Bolt11ParseError::MalformedSignature (
361 crate::c_types::Secp256k1Error::from_rust(a),
364 nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
365 nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
366 nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
367 nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
368 nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
369 nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
370 nativeBolt11ParseError::DescriptionDecodeError (mut a, ) => {
371 Bolt11ParseError::DescriptionDecodeError (
372 crate::c_types::Error { _dummy: 0 } /*a*/,
375 nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
376 nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
377 nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
378 nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
379 nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
380 nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
381 nativeBolt11ParseError::InvalidSliceLength (mut a, ) => {
382 Bolt11ParseError::InvalidSliceLength (
386 nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
390 /// Frees any resources used by the Bolt11ParseError
392 pub extern "C" fn Bolt11ParseError_free(this_ptr: Bolt11ParseError) { }
393 /// Creates a copy of the Bolt11ParseError
395 pub extern "C" fn Bolt11ParseError_clone(orig: &Bolt11ParseError) -> Bolt11ParseError {
399 /// Used only if an object of this type is returned as a trait impl by a method
400 pub(crate) extern "C" fn Bolt11ParseError_clone_void(this_ptr: *const c_void) -> *mut c_void {
401 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11ParseError)).clone() })) as *mut c_void
404 /// Used only if an object of this type is returned as a trait impl by a method
405 pub(crate) extern "C" fn Bolt11ParseError_free_void(this_ptr: *mut c_void) {
406 let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11ParseError) };
409 /// Utility method to constructs a new Bech32Error-variant Bolt11ParseError
410 pub extern "C" fn Bolt11ParseError_bech32_error(a: crate::c_types::Bech32Error) -> Bolt11ParseError {
411 Bolt11ParseError::Bech32Error(a, )
414 /// Utility method to constructs a new ParseAmountError-variant Bolt11ParseError
415 pub extern "C" fn Bolt11ParseError_parse_amount_error(a: crate::c_types::Error) -> Bolt11ParseError {
416 Bolt11ParseError::ParseAmountError(a, )
419 /// Utility method to constructs a new MalformedSignature-variant Bolt11ParseError
420 pub extern "C" fn Bolt11ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> Bolt11ParseError {
421 Bolt11ParseError::MalformedSignature(a, )
424 /// Utility method to constructs a new BadPrefix-variant Bolt11ParseError
425 pub extern "C" fn Bolt11ParseError_bad_prefix() -> Bolt11ParseError {
426 Bolt11ParseError::BadPrefix}
428 /// Utility method to constructs a new UnknownCurrency-variant Bolt11ParseError
429 pub extern "C" fn Bolt11ParseError_unknown_currency() -> Bolt11ParseError {
430 Bolt11ParseError::UnknownCurrency}
432 /// Utility method to constructs a new UnknownSiPrefix-variant Bolt11ParseError
433 pub extern "C" fn Bolt11ParseError_unknown_si_prefix() -> Bolt11ParseError {
434 Bolt11ParseError::UnknownSiPrefix}
436 /// Utility method to constructs a new MalformedHRP-variant Bolt11ParseError
437 pub extern "C" fn Bolt11ParseError_malformed_hrp() -> Bolt11ParseError {
438 Bolt11ParseError::MalformedHRP}
440 /// Utility method to constructs a new TooShortDataPart-variant Bolt11ParseError
441 pub extern "C" fn Bolt11ParseError_too_short_data_part() -> Bolt11ParseError {
442 Bolt11ParseError::TooShortDataPart}
444 /// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant Bolt11ParseError
445 pub extern "C" fn Bolt11ParseError_unexpected_end_of_tagged_fields() -> Bolt11ParseError {
446 Bolt11ParseError::UnexpectedEndOfTaggedFields}
448 /// Utility method to constructs a new DescriptionDecodeError-variant Bolt11ParseError
449 pub extern "C" fn Bolt11ParseError_description_decode_error(a: crate::c_types::Error) -> Bolt11ParseError {
450 Bolt11ParseError::DescriptionDecodeError(a, )
453 /// Utility method to constructs a new PaddingError-variant Bolt11ParseError
454 pub extern "C" fn Bolt11ParseError_padding_error() -> Bolt11ParseError {
455 Bolt11ParseError::PaddingError}
457 /// Utility method to constructs a new IntegerOverflowError-variant Bolt11ParseError
458 pub extern "C" fn Bolt11ParseError_integer_overflow_error() -> Bolt11ParseError {
459 Bolt11ParseError::IntegerOverflowError}
461 /// Utility method to constructs a new InvalidSegWitProgramLength-variant Bolt11ParseError
462 pub extern "C" fn Bolt11ParseError_invalid_seg_wit_program_length() -> Bolt11ParseError {
463 Bolt11ParseError::InvalidSegWitProgramLength}
465 /// Utility method to constructs a new InvalidPubKeyHashLength-variant Bolt11ParseError
466 pub extern "C" fn Bolt11ParseError_invalid_pub_key_hash_length() -> Bolt11ParseError {
467 Bolt11ParseError::InvalidPubKeyHashLength}
469 /// Utility method to constructs a new InvalidScriptHashLength-variant Bolt11ParseError
470 pub extern "C" fn Bolt11ParseError_invalid_script_hash_length() -> Bolt11ParseError {
471 Bolt11ParseError::InvalidScriptHashLength}
473 /// Utility method to constructs a new InvalidRecoveryId-variant Bolt11ParseError
474 pub extern "C" fn Bolt11ParseError_invalid_recovery_id() -> Bolt11ParseError {
475 Bolt11ParseError::InvalidRecoveryId}
477 /// Utility method to constructs a new InvalidSliceLength-variant Bolt11ParseError
478 pub extern "C" fn Bolt11ParseError_invalid_slice_length(a: crate::c_types::Str) -> Bolt11ParseError {
479 Bolt11ParseError::InvalidSliceLength(a, )
482 /// Utility method to constructs a new Skip-variant Bolt11ParseError
483 pub extern "C" fn Bolt11ParseError_skip() -> Bolt11ParseError {
484 Bolt11ParseError::Skip}
485 /// Checks if two Bolt11ParseErrors contain equal inner contents.
486 /// This ignores pointers and is_owned flags and looks at the values in fields.
488 pub extern "C" fn Bolt11ParseError_eq(a: &Bolt11ParseError, b: &Bolt11ParseError) -> bool {
489 if &a.to_native() == &b.to_native() { true } else { false }
491 /// Get a string which allows debug introspection of a Bolt11ParseError object
492 pub extern "C" fn Bolt11ParseError_debug_str_void(o: *const c_void) -> Str {
493 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11ParseError }).into()}
494 /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
495 /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
496 /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
500 pub enum ParseOrSemanticError {
501 /// The invoice couldn't be decoded
503 crate::lightning_invoice::Bolt11ParseError),
504 /// The invoice could be decoded but violates the BOLT11 standard
506 crate::lightning_invoice::Bolt11SemanticError),
508 use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
509 pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
511 impl ParseOrSemanticError {
513 pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
515 ParseOrSemanticError::ParseError (ref a, ) => {
516 let mut a_nonref = Clone::clone(a);
517 nativeParseOrSemanticError::ParseError (
518 a_nonref.into_native(),
521 ParseOrSemanticError::SemanticError (ref a, ) => {
522 let mut a_nonref = Clone::clone(a);
523 nativeParseOrSemanticError::SemanticError (
524 a_nonref.into_native(),
530 pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
532 ParseOrSemanticError::ParseError (mut a, ) => {
533 nativeParseOrSemanticError::ParseError (
537 ParseOrSemanticError::SemanticError (mut a, ) => {
538 nativeParseOrSemanticError::SemanticError (
545 pub(crate) fn from_native(native: &ParseOrSemanticErrorImport) -> Self {
546 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeParseOrSemanticError) };
548 nativeParseOrSemanticError::ParseError (ref a, ) => {
549 let mut a_nonref = Clone::clone(a);
550 ParseOrSemanticError::ParseError (
551 crate::lightning_invoice::Bolt11ParseError::native_into(a_nonref),
554 nativeParseOrSemanticError::SemanticError (ref a, ) => {
555 let mut a_nonref = Clone::clone(a);
556 ParseOrSemanticError::SemanticError (
557 crate::lightning_invoice::Bolt11SemanticError::native_into(a_nonref),
563 pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
565 nativeParseOrSemanticError::ParseError (mut a, ) => {
566 ParseOrSemanticError::ParseError (
567 crate::lightning_invoice::Bolt11ParseError::native_into(a),
570 nativeParseOrSemanticError::SemanticError (mut a, ) => {
571 ParseOrSemanticError::SemanticError (
572 crate::lightning_invoice::Bolt11SemanticError::native_into(a),
578 /// Frees any resources used by the ParseOrSemanticError
580 pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
581 /// Creates a copy of the ParseOrSemanticError
583 pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
587 /// Used only if an object of this type is returned as a trait impl by a method
588 pub(crate) extern "C" fn ParseOrSemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void {
589 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ParseOrSemanticError)).clone() })) as *mut c_void
592 /// Used only if an object of this type is returned as a trait impl by a method
593 pub(crate) extern "C" fn ParseOrSemanticError_free_void(this_ptr: *mut c_void) {
594 let _ = unsafe { Box::from_raw(this_ptr as *mut ParseOrSemanticError) };
597 /// Utility method to constructs a new ParseError-variant ParseOrSemanticError
598 pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::Bolt11ParseError) -> ParseOrSemanticError {
599 ParseOrSemanticError::ParseError(a, )
602 /// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
603 pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::Bolt11SemanticError) -> ParseOrSemanticError {
604 ParseOrSemanticError::SemanticError(a, )
606 /// Checks if two ParseOrSemanticErrors contain equal inner contents.
607 /// This ignores pointers and is_owned flags and looks at the values in fields.
609 pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
610 if &a.to_native() == &b.to_native() { true } else { false }
612 /// Get a string which allows debug introspection of a ParseOrSemanticError object
613 pub extern "C" fn ParseOrSemanticError_debug_str_void(o: *const c_void) -> Str {
614 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::ParseOrSemanticError }).into()}
615 /// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].
617 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
620 pub static MAX_TIMESTAMP: u64 = lightning_invoice::MAX_TIMESTAMP;
621 /// Default expiry time as defined by [BOLT 11].
623 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
626 pub static DEFAULT_EXPIRY_TIME: u64 = lightning_invoice::DEFAULT_EXPIRY_TIME;
627 /// Default minimum final CLTV expiry as defined by [BOLT 11].
629 /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
630 /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
632 /// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
633 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
636 pub static DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = lightning_invoice::DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA;
638 use lightning_invoice::Bolt11Invoice as nativeBolt11InvoiceImport;
639 pub(crate) type nativeBolt11Invoice = nativeBolt11InvoiceImport;
641 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
643 /// There are three ways to construct a `Bolt11Invoice`:
644 /// 1. using [`InvoiceBuilder`]
645 /// 2. using [`Bolt11Invoice::from_signed`]
646 /// 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
648 /// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
651 pub struct Bolt11Invoice {
652 /// A pointer to the opaque Rust object.
654 /// Nearly everywhere, inner must be non-null, however in places where
655 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
656 pub inner: *mut nativeBolt11Invoice,
657 /// Indicates that this is the only struct which contains the same pointer.
659 /// Rust functions which take ownership of an object provided via an argument require
660 /// this to be true and invalidate the object pointed to by inner.
664 impl Drop for Bolt11Invoice {
666 if self.is_owned && !<*mut nativeBolt11Invoice>::is_null(self.inner) {
667 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
671 /// Frees any resources used by the Bolt11Invoice, if is_owned is set and inner is non-NULL.
673 pub extern "C" fn Bolt11Invoice_free(this_obj: Bolt11Invoice) { }
675 /// Used only if an object of this type is returned as a trait impl by a method
676 pub(crate) extern "C" fn Bolt11Invoice_free_void(this_ptr: *mut c_void) {
677 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11Invoice) };
681 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11Invoice {
682 unsafe { &*ObjOps::untweak_ptr(self.inner) }
684 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11Invoice {
685 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
687 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
688 pub(crate) fn take_inner(mut self) -> *mut nativeBolt11Invoice {
689 assert!(self.is_owned);
690 let ret = ObjOps::untweak_ptr(self.inner);
691 self.inner = core::ptr::null_mut();
695 /// Checks if two Bolt11Invoices contain equal inner contents.
696 /// This ignores pointers and is_owned flags and looks at the values in fields.
697 /// Two objects with NULL inner values will be considered "equal" here.
699 pub extern "C" fn Bolt11Invoice_eq(a: &Bolt11Invoice, b: &Bolt11Invoice) -> bool {
700 if a.inner == b.inner { return true; }
701 if a.inner.is_null() || b.inner.is_null() { return false; }
702 if a.get_native_ref() == b.get_native_ref() { true } else { false }
704 /// Get a string which allows debug introspection of a Bolt11Invoice object
705 pub extern "C" fn Bolt11Invoice_debug_str_void(o: *const c_void) -> Str {
706 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11Invoice }).into()}
707 impl Clone for Bolt11Invoice {
708 fn clone(&self) -> Self {
710 inner: if <*mut nativeBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
711 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
717 /// Used only if an object of this type is returned as a trait impl by a method
718 pub(crate) extern "C" fn Bolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
719 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11Invoice)).clone() })) as *mut c_void
722 /// Creates a copy of the Bolt11Invoice
723 pub extern "C" fn Bolt11Invoice_clone(orig: &Bolt11Invoice) -> Bolt11Invoice {
726 /// Generates a non-cryptographic 64-bit hash of the Bolt11Invoice.
728 pub extern "C" fn Bolt11Invoice_hash(o: &Bolt11Invoice) -> u64 {
729 if o.inner.is_null() { return 0; }
730 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
732 let mut hasher = core::hash::SipHasher::new();
733 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
734 core::hash::Hasher::finish(&hasher)
737 use lightning_invoice::SignedRawBolt11Invoice as nativeSignedRawBolt11InvoiceImport;
738 pub(crate) type nativeSignedRawBolt11Invoice = nativeSignedRawBolt11InvoiceImport;
740 /// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
744 /// The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
747 pub struct SignedRawBolt11Invoice {
748 /// A pointer to the opaque Rust object.
750 /// Nearly everywhere, inner must be non-null, however in places where
751 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
752 pub inner: *mut nativeSignedRawBolt11Invoice,
753 /// Indicates that this is the only struct which contains the same pointer.
755 /// Rust functions which take ownership of an object provided via an argument require
756 /// this to be true and invalidate the object pointed to by inner.
760 impl Drop for SignedRawBolt11Invoice {
762 if self.is_owned && !<*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) {
763 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
767 /// Frees any resources used by the SignedRawBolt11Invoice, if is_owned is set and inner is non-NULL.
769 pub extern "C" fn SignedRawBolt11Invoice_free(this_obj: SignedRawBolt11Invoice) { }
771 /// Used only if an object of this type is returned as a trait impl by a method
772 pub(crate) extern "C" fn SignedRawBolt11Invoice_free_void(this_ptr: *mut c_void) {
773 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSignedRawBolt11Invoice) };
776 impl SignedRawBolt11Invoice {
777 pub(crate) fn get_native_ref(&self) -> &'static nativeSignedRawBolt11Invoice {
778 unsafe { &*ObjOps::untweak_ptr(self.inner) }
780 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSignedRawBolt11Invoice {
781 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
783 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
784 pub(crate) fn take_inner(mut self) -> *mut nativeSignedRawBolt11Invoice {
785 assert!(self.is_owned);
786 let ret = ObjOps::untweak_ptr(self.inner);
787 self.inner = core::ptr::null_mut();
791 /// Checks if two SignedRawBolt11Invoices contain equal inner contents.
792 /// This ignores pointers and is_owned flags and looks at the values in fields.
793 /// Two objects with NULL inner values will be considered "equal" here.
795 pub extern "C" fn SignedRawBolt11Invoice_eq(a: &SignedRawBolt11Invoice, b: &SignedRawBolt11Invoice) -> bool {
796 if a.inner == b.inner { return true; }
797 if a.inner.is_null() || b.inner.is_null() { return false; }
798 if a.get_native_ref() == b.get_native_ref() { true } else { false }
800 /// Get a string which allows debug introspection of a SignedRawBolt11Invoice object
801 pub extern "C" fn SignedRawBolt11Invoice_debug_str_void(o: *const c_void) -> Str {
802 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::SignedRawBolt11Invoice }).into()}
803 impl Clone for SignedRawBolt11Invoice {
804 fn clone(&self) -> Self {
806 inner: if <*mut nativeSignedRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
807 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
813 /// Used only if an object of this type is returned as a trait impl by a method
814 pub(crate) extern "C" fn SignedRawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
815 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSignedRawBolt11Invoice)).clone() })) as *mut c_void
818 /// Creates a copy of the SignedRawBolt11Invoice
819 pub extern "C" fn SignedRawBolt11Invoice_clone(orig: &SignedRawBolt11Invoice) -> SignedRawBolt11Invoice {
822 /// Generates a non-cryptographic 64-bit hash of the SignedRawBolt11Invoice.
824 pub extern "C" fn SignedRawBolt11Invoice_hash(o: &SignedRawBolt11Invoice) -> u64 {
825 if o.inner.is_null() { return 0; }
826 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
828 let mut hasher = core::hash::SipHasher::new();
829 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
830 core::hash::Hasher::finish(&hasher)
833 use lightning_invoice::RawBolt11Invoice as nativeRawBolt11InvoiceImport;
834 pub(crate) type nativeRawBolt11Invoice = nativeRawBolt11InvoiceImport;
836 /// Represents an syntactically correct [`Bolt11Invoice`] for a payment on the lightning network,
837 /// but without the signature information.
838 /// Decoding and encoding should not lead to information loss but may lead to different hashes.
840 /// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
843 pub struct RawBolt11Invoice {
844 /// A pointer to the opaque Rust object.
846 /// Nearly everywhere, inner must be non-null, however in places where
847 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
848 pub inner: *mut nativeRawBolt11Invoice,
849 /// Indicates that this is the only struct which contains the same pointer.
851 /// Rust functions which take ownership of an object provided via an argument require
852 /// this to be true and invalidate the object pointed to by inner.
856 impl Drop for RawBolt11Invoice {
858 if self.is_owned && !<*mut nativeRawBolt11Invoice>::is_null(self.inner) {
859 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
863 /// Frees any resources used by the RawBolt11Invoice, if is_owned is set and inner is non-NULL.
865 pub extern "C" fn RawBolt11Invoice_free(this_obj: RawBolt11Invoice) { }
867 /// Used only if an object of this type is returned as a trait impl by a method
868 pub(crate) extern "C" fn RawBolt11Invoice_free_void(this_ptr: *mut c_void) {
869 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawBolt11Invoice) };
872 impl RawBolt11Invoice {
873 pub(crate) fn get_native_ref(&self) -> &'static nativeRawBolt11Invoice {
874 unsafe { &*ObjOps::untweak_ptr(self.inner) }
876 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawBolt11Invoice {
877 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
879 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
880 pub(crate) fn take_inner(mut self) -> *mut nativeRawBolt11Invoice {
881 assert!(self.is_owned);
882 let ret = ObjOps::untweak_ptr(self.inner);
883 self.inner = core::ptr::null_mut();
889 pub extern "C" fn RawBolt11Invoice_get_data(this_ptr: &RawBolt11Invoice) -> crate::lightning_invoice::RawDataPart {
890 let mut inner_val = &mut this_ptr.get_native_mut_ref().data;
891 crate::lightning_invoice::RawDataPart { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::RawDataPart<>) as *mut _) }, is_owned: false }
895 pub extern "C" fn RawBolt11Invoice_set_data(this_ptr: &mut RawBolt11Invoice, mut val: crate::lightning_invoice::RawDataPart) {
896 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.data = *unsafe { Box::from_raw(val.take_inner()) };
898 /// Checks if two RawBolt11Invoices contain equal inner contents.
899 /// This ignores pointers and is_owned flags and looks at the values in fields.
900 /// Two objects with NULL inner values will be considered "equal" here.
902 pub extern "C" fn RawBolt11Invoice_eq(a: &RawBolt11Invoice, b: &RawBolt11Invoice) -> bool {
903 if a.inner == b.inner { return true; }
904 if a.inner.is_null() || b.inner.is_null() { return false; }
905 if a.get_native_ref() == b.get_native_ref() { true } else { false }
907 /// Get a string which allows debug introspection of a RawBolt11Invoice object
908 pub extern "C" fn RawBolt11Invoice_debug_str_void(o: *const c_void) -> Str {
909 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::RawBolt11Invoice }).into()}
910 impl Clone for RawBolt11Invoice {
911 fn clone(&self) -> Self {
913 inner: if <*mut nativeRawBolt11Invoice>::is_null(self.inner) { core::ptr::null_mut() } else {
914 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
920 /// Used only if an object of this type is returned as a trait impl by a method
921 pub(crate) extern "C" fn RawBolt11Invoice_clone_void(this_ptr: *const c_void) -> *mut c_void {
922 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRawBolt11Invoice)).clone() })) as *mut c_void
925 /// Creates a copy of the RawBolt11Invoice
926 pub extern "C" fn RawBolt11Invoice_clone(orig: &RawBolt11Invoice) -> RawBolt11Invoice {
929 /// Generates a non-cryptographic 64-bit hash of the RawBolt11Invoice.
931 pub extern "C" fn RawBolt11Invoice_hash(o: &RawBolt11Invoice) -> u64 {
932 if o.inner.is_null() { return 0; }
933 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
935 let mut hasher = core::hash::SipHasher::new();
936 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
937 core::hash::Hasher::finish(&hasher)
940 use lightning_invoice::RawDataPart as nativeRawDataPartImport;
941 pub(crate) type nativeRawDataPart = nativeRawDataPartImport;
943 /// Data of the [`RawBolt11Invoice`] that is encoded in the data part
946 pub struct RawDataPart {
947 /// A pointer to the opaque Rust object.
949 /// Nearly everywhere, inner must be non-null, however in places where
950 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
951 pub inner: *mut nativeRawDataPart,
952 /// Indicates that this is the only struct which contains the same pointer.
954 /// Rust functions which take ownership of an object provided via an argument require
955 /// this to be true and invalidate the object pointed to by inner.
959 impl Drop for RawDataPart {
961 if self.is_owned && !<*mut nativeRawDataPart>::is_null(self.inner) {
962 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
966 /// Frees any resources used by the RawDataPart, if is_owned is set and inner is non-NULL.
968 pub extern "C" fn RawDataPart_free(this_obj: RawDataPart) { }
970 /// Used only if an object of this type is returned as a trait impl by a method
971 pub(crate) extern "C" fn RawDataPart_free_void(this_ptr: *mut c_void) {
972 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRawDataPart) };
976 pub(crate) fn get_native_ref(&self) -> &'static nativeRawDataPart {
977 unsafe { &*ObjOps::untweak_ptr(self.inner) }
979 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRawDataPart {
980 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
982 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
983 pub(crate) fn take_inner(mut self) -> *mut nativeRawDataPart {
984 assert!(self.is_owned);
985 let ret = ObjOps::untweak_ptr(self.inner);
986 self.inner = core::ptr::null_mut();
990 /// generation time of the invoice
992 pub extern "C" fn RawDataPart_get_timestamp(this_ptr: &RawDataPart) -> crate::lightning_invoice::PositiveTimestamp {
993 let mut inner_val = &mut this_ptr.get_native_mut_ref().timestamp;
994 crate::lightning_invoice::PositiveTimestamp { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_invoice::PositiveTimestamp<>) as *mut _) }, is_owned: false }
996 /// generation time of the invoice
998 pub extern "C" fn RawDataPart_set_timestamp(this_ptr: &mut RawDataPart, mut val: crate::lightning_invoice::PositiveTimestamp) {
999 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = *unsafe { Box::from_raw(val.take_inner()) };
1001 /// Checks if two RawDataParts contain equal inner contents.
1002 /// This ignores pointers and is_owned flags and looks at the values in fields.
1003 /// Two objects with NULL inner values will be considered "equal" here.
1005 pub extern "C" fn RawDataPart_eq(a: &RawDataPart, b: &RawDataPart) -> bool {
1006 if a.inner == b.inner { return true; }
1007 if a.inner.is_null() || b.inner.is_null() { return false; }
1008 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1010 /// Get a string which allows debug introspection of a RawDataPart object
1011 pub extern "C" fn RawDataPart_debug_str_void(o: *const c_void) -> Str {
1012 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::RawDataPart }).into()}
1013 impl Clone for RawDataPart {
1014 fn clone(&self) -> Self {
1016 inner: if <*mut nativeRawDataPart>::is_null(self.inner) { core::ptr::null_mut() } else {
1017 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1023 /// Used only if an object of this type is returned as a trait impl by a method
1024 pub(crate) extern "C" fn RawDataPart_clone_void(this_ptr: *const c_void) -> *mut c_void {
1025 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRawDataPart)).clone() })) as *mut c_void
1028 /// Creates a copy of the RawDataPart
1029 pub extern "C" fn RawDataPart_clone(orig: &RawDataPart) -> RawDataPart {
1032 /// Generates a non-cryptographic 64-bit hash of the RawDataPart.
1034 pub extern "C" fn RawDataPart_hash(o: &RawDataPart) -> u64 {
1035 if o.inner.is_null() { return 0; }
1036 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1037 #[allow(deprecated)]
1038 let mut hasher = core::hash::SipHasher::new();
1039 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1040 core::hash::Hasher::finish(&hasher)
1043 use lightning_invoice::PositiveTimestamp as nativePositiveTimestampImport;
1044 pub(crate) type nativePositiveTimestamp = nativePositiveTimestampImport;
1046 /// A timestamp that refers to a date after 1 January 1970.
1050 /// The Unix timestamp representing the stored time has to be positive and no greater than
1051 /// [`MAX_TIMESTAMP`].
1054 pub struct PositiveTimestamp {
1055 /// A pointer to the opaque Rust object.
1057 /// Nearly everywhere, inner must be non-null, however in places where
1058 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1059 pub inner: *mut nativePositiveTimestamp,
1060 /// Indicates that this is the only struct which contains the same pointer.
1062 /// Rust functions which take ownership of an object provided via an argument require
1063 /// this to be true and invalidate the object pointed to by inner.
1067 impl Drop for PositiveTimestamp {
1068 fn drop(&mut self) {
1069 if self.is_owned && !<*mut nativePositiveTimestamp>::is_null(self.inner) {
1070 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1074 /// Frees any resources used by the PositiveTimestamp, if is_owned is set and inner is non-NULL.
1076 pub extern "C" fn PositiveTimestamp_free(this_obj: PositiveTimestamp) { }
1078 /// Used only if an object of this type is returned as a trait impl by a method
1079 pub(crate) extern "C" fn PositiveTimestamp_free_void(this_ptr: *mut c_void) {
1080 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePositiveTimestamp) };
1083 impl PositiveTimestamp {
1084 pub(crate) fn get_native_ref(&self) -> &'static nativePositiveTimestamp {
1085 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1087 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePositiveTimestamp {
1088 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1090 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1091 pub(crate) fn take_inner(mut self) -> *mut nativePositiveTimestamp {
1092 assert!(self.is_owned);
1093 let ret = ObjOps::untweak_ptr(self.inner);
1094 self.inner = core::ptr::null_mut();
1098 /// Checks if two PositiveTimestamps contain equal inner contents.
1099 /// This ignores pointers and is_owned flags and looks at the values in fields.
1100 /// Two objects with NULL inner values will be considered "equal" here.
1102 pub extern "C" fn PositiveTimestamp_eq(a: &PositiveTimestamp, b: &PositiveTimestamp) -> bool {
1103 if a.inner == b.inner { return true; }
1104 if a.inner.is_null() || b.inner.is_null() { return false; }
1105 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1107 /// Get a string which allows debug introspection of a PositiveTimestamp object
1108 pub extern "C" fn PositiveTimestamp_debug_str_void(o: *const c_void) -> Str {
1109 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::PositiveTimestamp }).into()}
1110 impl Clone for PositiveTimestamp {
1111 fn clone(&self) -> Self {
1113 inner: if <*mut nativePositiveTimestamp>::is_null(self.inner) { core::ptr::null_mut() } else {
1114 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1120 /// Used only if an object of this type is returned as a trait impl by a method
1121 pub(crate) extern "C" fn PositiveTimestamp_clone_void(this_ptr: *const c_void) -> *mut c_void {
1122 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePositiveTimestamp)).clone() })) as *mut c_void
1125 /// Creates a copy of the PositiveTimestamp
1126 pub extern "C" fn PositiveTimestamp_clone(orig: &PositiveTimestamp) -> PositiveTimestamp {
1129 /// Generates a non-cryptographic 64-bit hash of the PositiveTimestamp.
1131 pub extern "C" fn PositiveTimestamp_hash(o: &PositiveTimestamp) -> u64 {
1132 if o.inner.is_null() { return 0; }
1133 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1134 #[allow(deprecated)]
1135 let mut hasher = core::hash::SipHasher::new();
1136 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1137 core::hash::Hasher::finish(&hasher)
1139 /// SI prefixes for the human readable part
1153 use lightning_invoice::SiPrefix as SiPrefixImport;
1154 pub(crate) type nativeSiPrefix = SiPrefixImport;
1158 pub(crate) fn to_native(&self) -> nativeSiPrefix {
1160 SiPrefix::Milli => nativeSiPrefix::Milli,
1161 SiPrefix::Micro => nativeSiPrefix::Micro,
1162 SiPrefix::Nano => nativeSiPrefix::Nano,
1163 SiPrefix::Pico => nativeSiPrefix::Pico,
1167 pub(crate) fn into_native(self) -> nativeSiPrefix {
1169 SiPrefix::Milli => nativeSiPrefix::Milli,
1170 SiPrefix::Micro => nativeSiPrefix::Micro,
1171 SiPrefix::Nano => nativeSiPrefix::Nano,
1172 SiPrefix::Pico => nativeSiPrefix::Pico,
1176 pub(crate) fn from_native(native: &SiPrefixImport) -> Self {
1177 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSiPrefix) };
1179 nativeSiPrefix::Milli => SiPrefix::Milli,
1180 nativeSiPrefix::Micro => SiPrefix::Micro,
1181 nativeSiPrefix::Nano => SiPrefix::Nano,
1182 nativeSiPrefix::Pico => SiPrefix::Pico,
1186 pub(crate) fn native_into(native: nativeSiPrefix) -> Self {
1188 nativeSiPrefix::Milli => SiPrefix::Milli,
1189 nativeSiPrefix::Micro => SiPrefix::Micro,
1190 nativeSiPrefix::Nano => SiPrefix::Nano,
1191 nativeSiPrefix::Pico => SiPrefix::Pico,
1195 /// Creates a copy of the SiPrefix
1197 pub extern "C" fn SiPrefix_clone(orig: &SiPrefix) -> SiPrefix {
1201 /// Used only if an object of this type is returned as a trait impl by a method
1202 pub(crate) extern "C" fn SiPrefix_clone_void(this_ptr: *const c_void) -> *mut c_void {
1203 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SiPrefix)).clone() })) as *mut c_void
1206 /// Used only if an object of this type is returned as a trait impl by a method
1207 pub(crate) extern "C" fn SiPrefix_free_void(this_ptr: *mut c_void) {
1208 let _ = unsafe { Box::from_raw(this_ptr as *mut SiPrefix) };
1211 /// Utility method to constructs a new Milli-variant SiPrefix
1212 pub extern "C" fn SiPrefix_milli() -> SiPrefix {
1215 /// Utility method to constructs a new Micro-variant SiPrefix
1216 pub extern "C" fn SiPrefix_micro() -> SiPrefix {
1219 /// Utility method to constructs a new Nano-variant SiPrefix
1220 pub extern "C" fn SiPrefix_nano() -> SiPrefix {
1223 /// Utility method to constructs a new Pico-variant SiPrefix
1224 pub extern "C" fn SiPrefix_pico() -> SiPrefix {
1226 /// Checks if two SiPrefixs contain equal inner contents.
1227 /// This ignores pointers and is_owned flags and looks at the values in fields.
1229 pub extern "C" fn SiPrefix_eq(a: &SiPrefix, b: &SiPrefix) -> bool {
1230 if &a.to_native() == &b.to_native() { true } else { false }
1232 /// Get a string which allows debug introspection of a SiPrefix object
1233 pub extern "C" fn SiPrefix_debug_str_void(o: *const c_void) -> Str {
1234 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::SiPrefix }).into()}
1235 /// Generates a non-cryptographic 64-bit hash of the SiPrefix.
1237 pub extern "C" fn SiPrefix_hash(o: &SiPrefix) -> u64 {
1238 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1239 #[allow(deprecated)]
1240 let mut hasher = core::hash::SipHasher::new();
1241 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1242 core::hash::Hasher::finish(&hasher)
1244 /// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
1245 /// This is effectively 10^12 * the prefix multiplier
1248 pub extern "C" fn SiPrefix_multiplier(this_arg: &crate::lightning_invoice::SiPrefix) -> u64 {
1249 let mut ret = this_arg.to_native().multiplier();
1253 /// Enum representing the crypto currencies (or networks) supported by this library
1269 use lightning_invoice::Currency as CurrencyImport;
1270 pub(crate) type nativeCurrency = CurrencyImport;
1274 pub(crate) fn to_native(&self) -> nativeCurrency {
1276 Currency::Bitcoin => nativeCurrency::Bitcoin,
1277 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1278 Currency::Regtest => nativeCurrency::Regtest,
1279 Currency::Simnet => nativeCurrency::Simnet,
1280 Currency::Signet => nativeCurrency::Signet,
1284 pub(crate) fn into_native(self) -> nativeCurrency {
1286 Currency::Bitcoin => nativeCurrency::Bitcoin,
1287 Currency::BitcoinTestnet => nativeCurrency::BitcoinTestnet,
1288 Currency::Regtest => nativeCurrency::Regtest,
1289 Currency::Simnet => nativeCurrency::Simnet,
1290 Currency::Signet => nativeCurrency::Signet,
1294 pub(crate) fn from_native(native: &CurrencyImport) -> Self {
1295 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeCurrency) };
1297 nativeCurrency::Bitcoin => Currency::Bitcoin,
1298 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1299 nativeCurrency::Regtest => Currency::Regtest,
1300 nativeCurrency::Simnet => Currency::Simnet,
1301 nativeCurrency::Signet => Currency::Signet,
1305 pub(crate) fn native_into(native: nativeCurrency) -> Self {
1307 nativeCurrency::Bitcoin => Currency::Bitcoin,
1308 nativeCurrency::BitcoinTestnet => Currency::BitcoinTestnet,
1309 nativeCurrency::Regtest => Currency::Regtest,
1310 nativeCurrency::Simnet => Currency::Simnet,
1311 nativeCurrency::Signet => Currency::Signet,
1315 /// Creates a copy of the Currency
1317 pub extern "C" fn Currency_clone(orig: &Currency) -> Currency {
1321 /// Used only if an object of this type is returned as a trait impl by a method
1322 pub(crate) extern "C" fn Currency_clone_void(this_ptr: *const c_void) -> *mut c_void {
1323 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Currency)).clone() })) as *mut c_void
1326 /// Used only if an object of this type is returned as a trait impl by a method
1327 pub(crate) extern "C" fn Currency_free_void(this_ptr: *mut c_void) {
1328 let _ = unsafe { Box::from_raw(this_ptr as *mut Currency) };
1331 /// Utility method to constructs a new Bitcoin-variant Currency
1332 pub extern "C" fn Currency_bitcoin() -> Currency {
1335 /// Utility method to constructs a new BitcoinTestnet-variant Currency
1336 pub extern "C" fn Currency_bitcoin_testnet() -> Currency {
1337 Currency::BitcoinTestnet}
1339 /// Utility method to constructs a new Regtest-variant Currency
1340 pub extern "C" fn Currency_regtest() -> Currency {
1343 /// Utility method to constructs a new Simnet-variant Currency
1344 pub extern "C" fn Currency_simnet() -> Currency {
1347 /// Utility method to constructs a new Signet-variant Currency
1348 pub extern "C" fn Currency_signet() -> Currency {
1350 /// Get a string which allows debug introspection of a Currency object
1351 pub extern "C" fn Currency_debug_str_void(o: *const c_void) -> Str {
1352 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Currency }).into()}
1353 /// Generates a non-cryptographic 64-bit hash of the Currency.
1355 pub extern "C" fn Currency_hash(o: &Currency) -> u64 {
1356 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1357 #[allow(deprecated)]
1358 let mut hasher = core::hash::SipHasher::new();
1359 core::hash::Hash::hash(&o.to_native(), &mut hasher);
1360 core::hash::Hasher::finish(&hasher)
1362 /// Checks if two Currencys contain equal inner contents.
1363 /// This ignores pointers and is_owned flags and looks at the values in fields.
1365 pub extern "C" fn Currency_eq(a: &Currency, b: &Currency) -> bool {
1366 if &a.to_native() == &b.to_native() { true } else { false }
1369 use lightning_invoice::Sha256 as nativeSha256Import;
1370 pub(crate) type nativeSha256 = nativeSha256Import;
1376 /// A pointer to the opaque Rust object.
1378 /// Nearly everywhere, inner must be non-null, however in places where
1379 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1380 pub inner: *mut nativeSha256,
1381 /// Indicates that this is the only struct which contains the same pointer.
1383 /// Rust functions which take ownership of an object provided via an argument require
1384 /// this to be true and invalidate the object pointed to by inner.
1388 impl Drop for Sha256 {
1389 fn drop(&mut self) {
1390 if self.is_owned && !<*mut nativeSha256>::is_null(self.inner) {
1391 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1395 /// Frees any resources used by the Sha256, if is_owned is set and inner is non-NULL.
1397 pub extern "C" fn Sha256_free(this_obj: Sha256) { }
1399 /// Used only if an object of this type is returned as a trait impl by a method
1400 pub(crate) extern "C" fn Sha256_free_void(this_ptr: *mut c_void) {
1401 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSha256) };
1405 pub(crate) fn get_native_ref(&self) -> &'static nativeSha256 {
1406 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1408 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSha256 {
1409 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1411 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1412 pub(crate) fn take_inner(mut self) -> *mut nativeSha256 {
1413 assert!(self.is_owned);
1414 let ret = ObjOps::untweak_ptr(self.inner);
1415 self.inner = core::ptr::null_mut();
1419 impl Clone for Sha256 {
1420 fn clone(&self) -> Self {
1422 inner: if <*mut nativeSha256>::is_null(self.inner) { core::ptr::null_mut() } else {
1423 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1429 /// Used only if an object of this type is returned as a trait impl by a method
1430 pub(crate) extern "C" fn Sha256_clone_void(this_ptr: *const c_void) -> *mut c_void {
1431 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSha256)).clone() })) as *mut c_void
1434 /// Creates a copy of the Sha256
1435 pub extern "C" fn Sha256_clone(orig: &Sha256) -> Sha256 {
1438 /// Get a string which allows debug introspection of a Sha256 object
1439 pub extern "C" fn Sha256_debug_str_void(o: *const c_void) -> Str {
1440 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Sha256 }).into()}
1441 /// Generates a non-cryptographic 64-bit hash of the Sha256.
1443 pub extern "C" fn Sha256_hash(o: &Sha256) -> u64 {
1444 if o.inner.is_null() { return 0; }
1445 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1446 #[allow(deprecated)]
1447 let mut hasher = core::hash::SipHasher::new();
1448 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1449 core::hash::Hasher::finish(&hasher)
1451 /// Checks if two Sha256s contain equal inner contents.
1452 /// This ignores pointers and is_owned flags and looks at the values in fields.
1453 /// Two objects with NULL inner values will be considered "equal" here.
1455 pub extern "C" fn Sha256_eq(a: &Sha256, b: &Sha256) -> bool {
1456 if a.inner == b.inner { return true; }
1457 if a.inner.is_null() || b.inner.is_null() { return false; }
1458 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1460 /// Constructs a new [`Sha256`] from the given bytes, which are assumed to be the output of a
1461 /// single sha256 hash.
1464 pub extern "C" fn Sha256_from_bytes(bytes: *const [u8; 32]) -> crate::lightning_invoice::Sha256 {
1465 let mut ret = lightning_invoice::Sha256::from_bytes(unsafe { &*bytes});
1466 crate::lightning_invoice::Sha256 { inner: ObjOps::heap_alloc(ret), is_owned: true }
1470 use lightning_invoice::Description as nativeDescriptionImport;
1471 pub(crate) type nativeDescription = nativeDescriptionImport;
1473 /// Description string
1476 /// The description can be at most 639 __bytes__ long
1479 pub struct Description {
1480 /// A pointer to the opaque Rust object.
1482 /// Nearly everywhere, inner must be non-null, however in places where
1483 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1484 pub inner: *mut nativeDescription,
1485 /// Indicates that this is the only struct which contains the same pointer.
1487 /// Rust functions which take ownership of an object provided via an argument require
1488 /// this to be true and invalidate the object pointed to by inner.
1492 impl Drop for Description {
1493 fn drop(&mut self) {
1494 if self.is_owned && !<*mut nativeDescription>::is_null(self.inner) {
1495 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1499 /// Frees any resources used by the Description, if is_owned is set and inner is non-NULL.
1501 pub extern "C" fn Description_free(this_obj: Description) { }
1503 /// Used only if an object of this type is returned as a trait impl by a method
1504 pub(crate) extern "C" fn Description_free_void(this_ptr: *mut c_void) {
1505 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDescription) };
1509 pub(crate) fn get_native_ref(&self) -> &'static nativeDescription {
1510 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1512 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDescription {
1513 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1515 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1516 pub(crate) fn take_inner(mut self) -> *mut nativeDescription {
1517 assert!(self.is_owned);
1518 let ret = ObjOps::untweak_ptr(self.inner);
1519 self.inner = core::ptr::null_mut();
1523 impl Clone for Description {
1524 fn clone(&self) -> Self {
1526 inner: if <*mut nativeDescription>::is_null(self.inner) { core::ptr::null_mut() } else {
1527 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1533 /// Used only if an object of this type is returned as a trait impl by a method
1534 pub(crate) extern "C" fn Description_clone_void(this_ptr: *const c_void) -> *mut c_void {
1535 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDescription)).clone() })) as *mut c_void
1538 /// Creates a copy of the Description
1539 pub extern "C" fn Description_clone(orig: &Description) -> Description {
1542 /// Get a string which allows debug introspection of a Description object
1543 pub extern "C" fn Description_debug_str_void(o: *const c_void) -> Str {
1544 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Description }).into()}
1545 /// Generates a non-cryptographic 64-bit hash of the Description.
1547 pub extern "C" fn Description_hash(o: &Description) -> u64 {
1548 if o.inner.is_null() { return 0; }
1549 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1550 #[allow(deprecated)]
1551 let mut hasher = core::hash::SipHasher::new();
1552 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1553 core::hash::Hasher::finish(&hasher)
1555 /// Checks if two Descriptions contain equal inner contents.
1556 /// This ignores pointers and is_owned flags and looks at the values in fields.
1557 /// Two objects with NULL inner values will be considered "equal" here.
1559 pub extern "C" fn Description_eq(a: &Description, b: &Description) -> bool {
1560 if a.inner == b.inner { return true; }
1561 if a.inner.is_null() || b.inner.is_null() { return false; }
1562 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1565 use lightning_invoice::PayeePubKey as nativePayeePubKeyImport;
1566 pub(crate) type nativePayeePubKey = nativePayeePubKeyImport;
1568 /// Payee public key
1571 pub struct PayeePubKey {
1572 /// A pointer to the opaque Rust object.
1574 /// Nearly everywhere, inner must be non-null, however in places where
1575 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1576 pub inner: *mut nativePayeePubKey,
1577 /// Indicates that this is the only struct which contains the same pointer.
1579 /// Rust functions which take ownership of an object provided via an argument require
1580 /// this to be true and invalidate the object pointed to by inner.
1584 impl Drop for PayeePubKey {
1585 fn drop(&mut self) {
1586 if self.is_owned && !<*mut nativePayeePubKey>::is_null(self.inner) {
1587 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1591 /// Frees any resources used by the PayeePubKey, if is_owned is set and inner is non-NULL.
1593 pub extern "C" fn PayeePubKey_free(this_obj: PayeePubKey) { }
1595 /// Used only if an object of this type is returned as a trait impl by a method
1596 pub(crate) extern "C" fn PayeePubKey_free_void(this_ptr: *mut c_void) {
1597 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePayeePubKey) };
1601 pub(crate) fn get_native_ref(&self) -> &'static nativePayeePubKey {
1602 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1604 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePayeePubKey {
1605 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1607 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1608 pub(crate) fn take_inner(mut self) -> *mut nativePayeePubKey {
1609 assert!(self.is_owned);
1610 let ret = ObjOps::untweak_ptr(self.inner);
1611 self.inner = core::ptr::null_mut();
1616 pub extern "C" fn PayeePubKey_get_a(this_ptr: &PayeePubKey) -> crate::c_types::PublicKey {
1617 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1618 crate::c_types::PublicKey::from_rust(&inner_val)
1621 pub extern "C" fn PayeePubKey_set_a(this_ptr: &mut PayeePubKey, mut val: crate::c_types::PublicKey) {
1622 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
1624 /// Constructs a new PayeePubKey given each field
1627 pub extern "C" fn PayeePubKey_new(mut a_arg: crate::c_types::PublicKey) -> PayeePubKey {
1628 PayeePubKey { inner: ObjOps::heap_alloc(lightning_invoice::PayeePubKey (
1630 )), is_owned: true }
1632 impl Clone for PayeePubKey {
1633 fn clone(&self) -> Self {
1635 inner: if <*mut nativePayeePubKey>::is_null(self.inner) { core::ptr::null_mut() } else {
1636 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1642 /// Used only if an object of this type is returned as a trait impl by a method
1643 pub(crate) extern "C" fn PayeePubKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
1644 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePayeePubKey)).clone() })) as *mut c_void
1647 /// Creates a copy of the PayeePubKey
1648 pub extern "C" fn PayeePubKey_clone(orig: &PayeePubKey) -> PayeePubKey {
1651 /// Get a string which allows debug introspection of a PayeePubKey object
1652 pub extern "C" fn PayeePubKey_debug_str_void(o: *const c_void) -> Str {
1653 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::PayeePubKey }).into()}
1654 /// Generates a non-cryptographic 64-bit hash of the PayeePubKey.
1656 pub extern "C" fn PayeePubKey_hash(o: &PayeePubKey) -> u64 {
1657 if o.inner.is_null() { return 0; }
1658 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1659 #[allow(deprecated)]
1660 let mut hasher = core::hash::SipHasher::new();
1661 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1662 core::hash::Hasher::finish(&hasher)
1664 /// Checks if two PayeePubKeys contain equal inner contents.
1665 /// This ignores pointers and is_owned flags and looks at the values in fields.
1666 /// Two objects with NULL inner values will be considered "equal" here.
1668 pub extern "C" fn PayeePubKey_eq(a: &PayeePubKey, b: &PayeePubKey) -> bool {
1669 if a.inner == b.inner { return true; }
1670 if a.inner.is_null() || b.inner.is_null() { return false; }
1671 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1674 use lightning_invoice::ExpiryTime as nativeExpiryTimeImport;
1675 pub(crate) type nativeExpiryTime = nativeExpiryTimeImport;
1677 /// Positive duration that defines when (relatively to the timestamp) in the future the invoice
1681 pub struct ExpiryTime {
1682 /// A pointer to the opaque Rust object.
1684 /// Nearly everywhere, inner must be non-null, however in places where
1685 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1686 pub inner: *mut nativeExpiryTime,
1687 /// Indicates that this is the only struct which contains the same pointer.
1689 /// Rust functions which take ownership of an object provided via an argument require
1690 /// this to be true and invalidate the object pointed to by inner.
1694 impl Drop for ExpiryTime {
1695 fn drop(&mut self) {
1696 if self.is_owned && !<*mut nativeExpiryTime>::is_null(self.inner) {
1697 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1701 /// Frees any resources used by the ExpiryTime, if is_owned is set and inner is non-NULL.
1703 pub extern "C" fn ExpiryTime_free(this_obj: ExpiryTime) { }
1705 /// Used only if an object of this type is returned as a trait impl by a method
1706 pub(crate) extern "C" fn ExpiryTime_free_void(this_ptr: *mut c_void) {
1707 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpiryTime) };
1711 pub(crate) fn get_native_ref(&self) -> &'static nativeExpiryTime {
1712 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1714 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpiryTime {
1715 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1717 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1718 pub(crate) fn take_inner(mut self) -> *mut nativeExpiryTime {
1719 assert!(self.is_owned);
1720 let ret = ObjOps::untweak_ptr(self.inner);
1721 self.inner = core::ptr::null_mut();
1725 impl Clone for ExpiryTime {
1726 fn clone(&self) -> Self {
1728 inner: if <*mut nativeExpiryTime>::is_null(self.inner) { core::ptr::null_mut() } else {
1729 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1735 /// Used only if an object of this type is returned as a trait impl by a method
1736 pub(crate) extern "C" fn ExpiryTime_clone_void(this_ptr: *const c_void) -> *mut c_void {
1737 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeExpiryTime)).clone() })) as *mut c_void
1740 /// Creates a copy of the ExpiryTime
1741 pub extern "C" fn ExpiryTime_clone(orig: &ExpiryTime) -> ExpiryTime {
1744 /// Get a string which allows debug introspection of a ExpiryTime object
1745 pub extern "C" fn ExpiryTime_debug_str_void(o: *const c_void) -> Str {
1746 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::ExpiryTime }).into()}
1747 /// Generates a non-cryptographic 64-bit hash of the ExpiryTime.
1749 pub extern "C" fn ExpiryTime_hash(o: &ExpiryTime) -> u64 {
1750 if o.inner.is_null() { return 0; }
1751 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1752 #[allow(deprecated)]
1753 let mut hasher = core::hash::SipHasher::new();
1754 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1755 core::hash::Hasher::finish(&hasher)
1757 /// Checks if two ExpiryTimes contain equal inner contents.
1758 /// This ignores pointers and is_owned flags and looks at the values in fields.
1759 /// Two objects with NULL inner values will be considered "equal" here.
1761 pub extern "C" fn ExpiryTime_eq(a: &ExpiryTime, b: &ExpiryTime) -> bool {
1762 if a.inner == b.inner { return true; }
1763 if a.inner.is_null() || b.inner.is_null() { return false; }
1764 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1767 use lightning_invoice::MinFinalCltvExpiryDelta as nativeMinFinalCltvExpiryDeltaImport;
1768 pub(crate) type nativeMinFinalCltvExpiryDelta = nativeMinFinalCltvExpiryDeltaImport;
1770 /// `min_final_cltv_expiry_delta` to use for the last HTLC in the route
1773 pub struct MinFinalCltvExpiryDelta {
1774 /// A pointer to the opaque Rust object.
1776 /// Nearly everywhere, inner must be non-null, however in places where
1777 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1778 pub inner: *mut nativeMinFinalCltvExpiryDelta,
1779 /// Indicates that this is the only struct which contains the same pointer.
1781 /// Rust functions which take ownership of an object provided via an argument require
1782 /// this to be true and invalidate the object pointed to by inner.
1786 impl Drop for MinFinalCltvExpiryDelta {
1787 fn drop(&mut self) {
1788 if self.is_owned && !<*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) {
1789 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1793 /// Frees any resources used by the MinFinalCltvExpiryDelta, if is_owned is set and inner is non-NULL.
1795 pub extern "C" fn MinFinalCltvExpiryDelta_free(this_obj: MinFinalCltvExpiryDelta) { }
1797 /// Used only if an object of this type is returned as a trait impl by a method
1798 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_free_void(this_ptr: *mut c_void) {
1799 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMinFinalCltvExpiryDelta) };
1802 impl MinFinalCltvExpiryDelta {
1803 pub(crate) fn get_native_ref(&self) -> &'static nativeMinFinalCltvExpiryDelta {
1804 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1806 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMinFinalCltvExpiryDelta {
1807 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1809 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1810 pub(crate) fn take_inner(mut self) -> *mut nativeMinFinalCltvExpiryDelta {
1811 assert!(self.is_owned);
1812 let ret = ObjOps::untweak_ptr(self.inner);
1813 self.inner = core::ptr::null_mut();
1818 pub extern "C" fn MinFinalCltvExpiryDelta_get_a(this_ptr: &MinFinalCltvExpiryDelta) -> u64 {
1819 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
1823 pub extern "C" fn MinFinalCltvExpiryDelta_set_a(this_ptr: &mut MinFinalCltvExpiryDelta, mut val: u64) {
1824 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
1826 /// Constructs a new MinFinalCltvExpiryDelta given each field
1829 pub extern "C" fn MinFinalCltvExpiryDelta_new(mut a_arg: u64) -> MinFinalCltvExpiryDelta {
1830 MinFinalCltvExpiryDelta { inner: ObjOps::heap_alloc(lightning_invoice::MinFinalCltvExpiryDelta (
1832 )), is_owned: true }
1834 impl Clone for MinFinalCltvExpiryDelta {
1835 fn clone(&self) -> Self {
1837 inner: if <*mut nativeMinFinalCltvExpiryDelta>::is_null(self.inner) { core::ptr::null_mut() } else {
1838 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1844 /// Used only if an object of this type is returned as a trait impl by a method
1845 pub(crate) extern "C" fn MinFinalCltvExpiryDelta_clone_void(this_ptr: *const c_void) -> *mut c_void {
1846 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeMinFinalCltvExpiryDelta)).clone() })) as *mut c_void
1849 /// Creates a copy of the MinFinalCltvExpiryDelta
1850 pub extern "C" fn MinFinalCltvExpiryDelta_clone(orig: &MinFinalCltvExpiryDelta) -> MinFinalCltvExpiryDelta {
1853 /// Get a string which allows debug introspection of a MinFinalCltvExpiryDelta object
1854 pub extern "C" fn MinFinalCltvExpiryDelta_debug_str_void(o: *const c_void) -> Str {
1855 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::MinFinalCltvExpiryDelta }).into()}
1856 /// Generates a non-cryptographic 64-bit hash of the MinFinalCltvExpiryDelta.
1858 pub extern "C" fn MinFinalCltvExpiryDelta_hash(o: &MinFinalCltvExpiryDelta) -> u64 {
1859 if o.inner.is_null() { return 0; }
1860 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
1861 #[allow(deprecated)]
1862 let mut hasher = core::hash::SipHasher::new();
1863 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
1864 core::hash::Hasher::finish(&hasher)
1866 /// Checks if two MinFinalCltvExpiryDeltas contain equal inner contents.
1867 /// This ignores pointers and is_owned flags and looks at the values in fields.
1868 /// Two objects with NULL inner values will be considered "equal" here.
1870 pub extern "C" fn MinFinalCltvExpiryDelta_eq(a: &MinFinalCltvExpiryDelta, b: &MinFinalCltvExpiryDelta) -> bool {
1871 if a.inner == b.inner { return true; }
1872 if a.inner.is_null() || b.inner.is_null() { return false; }
1873 if a.get_native_ref() == b.get_native_ref() { true } else { false }
1875 /// Fallback address in case no LN payment is possible
1881 version: crate::c_types::WitnessVersion,
1882 program: crate::c_types::derived::CVec_u8Z,
1885 crate::c_types::TwentyBytes),
1887 crate::c_types::TwentyBytes),
1889 use lightning_invoice::Fallback as FallbackImport;
1890 pub(crate) type nativeFallback = FallbackImport;
1894 pub(crate) fn to_native(&self) -> nativeFallback {
1896 Fallback::SegWitProgram {ref version, ref program, } => {
1897 let mut version_nonref = Clone::clone(version);
1898 let mut program_nonref = Clone::clone(program);
1899 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.into_rust().drain(..) { local_program_nonref.push( { item }); };
1900 nativeFallback::SegWitProgram {
1901 version: version_nonref.into(),
1902 program: local_program_nonref,
1905 Fallback::PubKeyHash (ref a, ) => {
1906 let mut a_nonref = Clone::clone(a);
1907 nativeFallback::PubKeyHash (
1908 bitcoin::hash_types::PubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a_nonref.data)),
1911 Fallback::ScriptHash (ref a, ) => {
1912 let mut a_nonref = Clone::clone(a);
1913 nativeFallback::ScriptHash (
1914 bitcoin::hash_types::ScriptHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a_nonref.data)),
1920 pub(crate) fn into_native(self) -> nativeFallback {
1922 Fallback::SegWitProgram {mut version, mut program, } => {
1923 let mut local_program = Vec::new(); for mut item in program.into_rust().drain(..) { local_program.push( { item }); };
1924 nativeFallback::SegWitProgram {
1925 version: version.into(),
1926 program: local_program,
1929 Fallback::PubKeyHash (mut a, ) => {
1930 nativeFallback::PubKeyHash (
1931 bitcoin::hash_types::PubkeyHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a.data)),
1934 Fallback::ScriptHash (mut a, ) => {
1935 nativeFallback::ScriptHash (
1936 bitcoin::hash_types::ScriptHash::from_raw_hash(bitcoin::hashes::Hash::from_byte_array(a.data)),
1942 pub(crate) fn from_native(native: &FallbackImport) -> Self {
1943 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeFallback) };
1945 nativeFallback::SegWitProgram {ref version, ref program, } => {
1946 let mut version_nonref = Clone::clone(version);
1947 let mut program_nonref = Clone::clone(program);
1948 let mut local_program_nonref = Vec::new(); for mut item in program_nonref.drain(..) { local_program_nonref.push( { item }); };
1949 Fallback::SegWitProgram {
1950 version: version_nonref.into(),
1951 program: local_program_nonref.into(),
1954 nativeFallback::PubKeyHash (ref a, ) => {
1955 let mut a_nonref = Clone::clone(a);
1956 Fallback::PubKeyHash (
1957 crate::c_types::TwentyBytes { data: *a_nonref.as_ref() },
1960 nativeFallback::ScriptHash (ref a, ) => {
1961 let mut a_nonref = Clone::clone(a);
1962 Fallback::ScriptHash (
1963 crate::c_types::TwentyBytes { data: *a_nonref.as_ref() },
1969 pub(crate) fn native_into(native: nativeFallback) -> Self {
1971 nativeFallback::SegWitProgram {mut version, mut program, } => {
1972 let mut local_program = Vec::new(); for mut item in program.drain(..) { local_program.push( { item }); };
1973 Fallback::SegWitProgram {
1974 version: version.into(),
1975 program: local_program.into(),
1978 nativeFallback::PubKeyHash (mut a, ) => {
1979 Fallback::PubKeyHash (
1980 crate::c_types::TwentyBytes { data: *a.as_ref() },
1983 nativeFallback::ScriptHash (mut a, ) => {
1984 Fallback::ScriptHash (
1985 crate::c_types::TwentyBytes { data: *a.as_ref() },
1991 /// Frees any resources used by the Fallback
1993 pub extern "C" fn Fallback_free(this_ptr: Fallback) { }
1994 /// Creates a copy of the Fallback
1996 pub extern "C" fn Fallback_clone(orig: &Fallback) -> Fallback {
2000 /// Used only if an object of this type is returned as a trait impl by a method
2001 pub(crate) extern "C" fn Fallback_clone_void(this_ptr: *const c_void) -> *mut c_void {
2002 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Fallback)).clone() })) as *mut c_void
2005 /// Used only if an object of this type is returned as a trait impl by a method
2006 pub(crate) extern "C" fn Fallback_free_void(this_ptr: *mut c_void) {
2007 let _ = unsafe { Box::from_raw(this_ptr as *mut Fallback) };
2010 /// Utility method to constructs a new SegWitProgram-variant Fallback
2011 pub extern "C" fn Fallback_seg_wit_program(version: crate::c_types::WitnessVersion, program: crate::c_types::derived::CVec_u8Z) -> Fallback {
2012 Fallback::SegWitProgram {
2018 /// Utility method to constructs a new PubKeyHash-variant Fallback
2019 pub extern "C" fn Fallback_pub_key_hash(a: crate::c_types::TwentyBytes) -> Fallback {
2020 Fallback::PubKeyHash(a, )
2023 /// Utility method to constructs a new ScriptHash-variant Fallback
2024 pub extern "C" fn Fallback_script_hash(a: crate::c_types::TwentyBytes) -> Fallback {
2025 Fallback::ScriptHash(a, )
2027 /// Get a string which allows debug introspection of a Fallback object
2028 pub extern "C" fn Fallback_debug_str_void(o: *const c_void) -> Str {
2029 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Fallback }).into()}
2030 /// Generates a non-cryptographic 64-bit hash of the Fallback.
2032 pub extern "C" fn Fallback_hash(o: &Fallback) -> u64 {
2033 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2034 #[allow(deprecated)]
2035 let mut hasher = core::hash::SipHasher::new();
2036 core::hash::Hash::hash(&o.to_native(), &mut hasher);
2037 core::hash::Hasher::finish(&hasher)
2039 /// Checks if two Fallbacks contain equal inner contents.
2040 /// This ignores pointers and is_owned flags and looks at the values in fields.
2042 pub extern "C" fn Fallback_eq(a: &Fallback, b: &Fallback) -> bool {
2043 if &a.to_native() == &b.to_native() { true } else { false }
2046 use lightning_invoice::Bolt11InvoiceSignature as nativeBolt11InvoiceSignatureImport;
2047 pub(crate) type nativeBolt11InvoiceSignature = nativeBolt11InvoiceSignatureImport;
2049 /// Recoverable signature
2052 pub struct Bolt11InvoiceSignature {
2053 /// A pointer to the opaque Rust object.
2055 /// Nearly everywhere, inner must be non-null, however in places where
2056 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2057 pub inner: *mut nativeBolt11InvoiceSignature,
2058 /// Indicates that this is the only struct which contains the same pointer.
2060 /// Rust functions which take ownership of an object provided via an argument require
2061 /// this to be true and invalidate the object pointed to by inner.
2065 impl Drop for Bolt11InvoiceSignature {
2066 fn drop(&mut self) {
2067 if self.is_owned && !<*mut nativeBolt11InvoiceSignature>::is_null(self.inner) {
2068 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2072 /// Frees any resources used by the Bolt11InvoiceSignature, if is_owned is set and inner is non-NULL.
2074 pub extern "C" fn Bolt11InvoiceSignature_free(this_obj: Bolt11InvoiceSignature) { }
2076 /// Used only if an object of this type is returned as a trait impl by a method
2077 pub(crate) extern "C" fn Bolt11InvoiceSignature_free_void(this_ptr: *mut c_void) {
2078 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeBolt11InvoiceSignature) };
2081 impl Bolt11InvoiceSignature {
2082 pub(crate) fn get_native_ref(&self) -> &'static nativeBolt11InvoiceSignature {
2083 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2085 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBolt11InvoiceSignature {
2086 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2088 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2089 pub(crate) fn take_inner(mut self) -> *mut nativeBolt11InvoiceSignature {
2090 assert!(self.is_owned);
2091 let ret = ObjOps::untweak_ptr(self.inner);
2092 self.inner = core::ptr::null_mut();
2096 impl Clone for Bolt11InvoiceSignature {
2097 fn clone(&self) -> Self {
2099 inner: if <*mut nativeBolt11InvoiceSignature>::is_null(self.inner) { core::ptr::null_mut() } else {
2100 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2106 /// Used only if an object of this type is returned as a trait impl by a method
2107 pub(crate) extern "C" fn Bolt11InvoiceSignature_clone_void(this_ptr: *const c_void) -> *mut c_void {
2108 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeBolt11InvoiceSignature)).clone() })) as *mut c_void
2111 /// Creates a copy of the Bolt11InvoiceSignature
2112 pub extern "C" fn Bolt11InvoiceSignature_clone(orig: &Bolt11InvoiceSignature) -> Bolt11InvoiceSignature {
2115 /// Get a string which allows debug introspection of a Bolt11InvoiceSignature object
2116 pub extern "C" fn Bolt11InvoiceSignature_debug_str_void(o: *const c_void) -> Str {
2117 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11InvoiceSignature }).into()}
2118 /// Generates a non-cryptographic 64-bit hash of the Bolt11InvoiceSignature.
2120 pub extern "C" fn Bolt11InvoiceSignature_hash(o: &Bolt11InvoiceSignature) -> u64 {
2121 if o.inner.is_null() { return 0; }
2122 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2123 #[allow(deprecated)]
2124 let mut hasher = core::hash::SipHasher::new();
2125 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2126 core::hash::Hasher::finish(&hasher)
2128 /// Checks if two Bolt11InvoiceSignatures contain equal inner contents.
2129 /// This ignores pointers and is_owned flags and looks at the values in fields.
2130 /// Two objects with NULL inner values will be considered "equal" here.
2132 pub extern "C" fn Bolt11InvoiceSignature_eq(a: &Bolt11InvoiceSignature, b: &Bolt11InvoiceSignature) -> bool {
2133 if a.inner == b.inner { return true; }
2134 if a.inner.is_null() || b.inner.is_null() { return false; }
2135 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2138 use lightning_invoice::PrivateRoute as nativePrivateRouteImport;
2139 pub(crate) type nativePrivateRoute = nativePrivateRouteImport;
2141 /// Private routing information
2144 /// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
2148 pub struct PrivateRoute {
2149 /// A pointer to the opaque Rust object.
2151 /// Nearly everywhere, inner must be non-null, however in places where
2152 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
2153 pub inner: *mut nativePrivateRoute,
2154 /// Indicates that this is the only struct which contains the same pointer.
2156 /// Rust functions which take ownership of an object provided via an argument require
2157 /// this to be true and invalidate the object pointed to by inner.
2161 impl Drop for PrivateRoute {
2162 fn drop(&mut self) {
2163 if self.is_owned && !<*mut nativePrivateRoute>::is_null(self.inner) {
2164 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
2168 /// Frees any resources used by the PrivateRoute, if is_owned is set and inner is non-NULL.
2170 pub extern "C" fn PrivateRoute_free(this_obj: PrivateRoute) { }
2172 /// Used only if an object of this type is returned as a trait impl by a method
2173 pub(crate) extern "C" fn PrivateRoute_free_void(this_ptr: *mut c_void) {
2174 let _ = unsafe { Box::from_raw(this_ptr as *mut nativePrivateRoute) };
2178 pub(crate) fn get_native_ref(&self) -> &'static nativePrivateRoute {
2179 unsafe { &*ObjOps::untweak_ptr(self.inner) }
2181 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativePrivateRoute {
2182 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
2184 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
2185 pub(crate) fn take_inner(mut self) -> *mut nativePrivateRoute {
2186 assert!(self.is_owned);
2187 let ret = ObjOps::untweak_ptr(self.inner);
2188 self.inner = core::ptr::null_mut();
2192 impl Clone for PrivateRoute {
2193 fn clone(&self) -> Self {
2195 inner: if <*mut nativePrivateRoute>::is_null(self.inner) { core::ptr::null_mut() } else {
2196 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
2202 /// Used only if an object of this type is returned as a trait impl by a method
2203 pub(crate) extern "C" fn PrivateRoute_clone_void(this_ptr: *const c_void) -> *mut c_void {
2204 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePrivateRoute)).clone() })) as *mut c_void
2207 /// Creates a copy of the PrivateRoute
2208 pub extern "C" fn PrivateRoute_clone(orig: &PrivateRoute) -> PrivateRoute {
2211 /// Get a string which allows debug introspection of a PrivateRoute object
2212 pub extern "C" fn PrivateRoute_debug_str_void(o: *const c_void) -> Str {
2213 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::PrivateRoute }).into()}
2214 /// Generates a non-cryptographic 64-bit hash of the PrivateRoute.
2216 pub extern "C" fn PrivateRoute_hash(o: &PrivateRoute) -> u64 {
2217 if o.inner.is_null() { return 0; }
2218 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
2219 #[allow(deprecated)]
2220 let mut hasher = core::hash::SipHasher::new();
2221 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
2222 core::hash::Hasher::finish(&hasher)
2224 /// Checks if two PrivateRoutes contain equal inner contents.
2225 /// This ignores pointers and is_owned flags and looks at the values in fields.
2226 /// Two objects with NULL inner values will be considered "equal" here.
2228 pub extern "C" fn PrivateRoute_eq(a: &PrivateRoute, b: &PrivateRoute) -> bool {
2229 if a.inner == b.inner { return true; }
2230 if a.inner.is_null() || b.inner.is_null() { return false; }
2231 if a.get_native_ref() == b.get_native_ref() { true } else { false }
2233 /// Disassembles the `SignedRawBolt11Invoice` into its three parts:
2235 /// 2. hash of the raw invoice
2239 pub extern "C" fn SignedRawBolt11Invoice_into_parts(mut this_arg: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::C3Tuple_RawBolt11Invoice_u832Bolt11InvoiceSignatureZ {
2240 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_parts();
2241 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();
2245 /// The [`RawBolt11Invoice`] which was signed.
2248 pub extern "C" fn SignedRawBolt11Invoice_raw_invoice(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::RawBolt11Invoice {
2249 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.raw_invoice();
2250 crate::lightning_invoice::RawBolt11Invoice { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::RawBolt11Invoice<>) as *mut _) }, is_owned: false }
2253 /// The hash of the [`RawBolt11Invoice`] that was signed.
2256 pub extern "C" fn SignedRawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> *const [u8; 32] {
2257 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2261 /// Signature for the invoice.
2264 pub extern "C" fn SignedRawBolt11Invoice_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::lightning_invoice::Bolt11InvoiceSignature {
2265 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signature();
2266 crate::lightning_invoice::Bolt11InvoiceSignature { inner: unsafe { ObjOps::nonnull_ptr_to_inner((ret as *const lightning_invoice::Bolt11InvoiceSignature<>) as *mut _) }, is_owned: false }
2269 /// Recovers the public key used for signing the invoice from the recoverable signature.
2272 pub extern "C" fn SignedRawBolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_PayeePubKeySecp256k1ErrorZ {
2273 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2274 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() };
2278 /// Checks if the signature is valid for the included payee public key or if none exists if it's
2279 /// valid for the recovered signature (which should always be true?).
2282 pub extern "C" fn SignedRawBolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::SignedRawBolt11Invoice) -> bool {
2283 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2287 /// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
2290 pub extern "C" fn RawBolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
2291 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2292 crate::c_types::ThirtyTwoBytes { data: ret }
2296 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2299 pub extern "C" fn RawBolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Sha256 {
2300 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2301 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 };
2306 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2309 pub extern "C" fn RawBolt11Invoice_description(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Description {
2310 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description();
2311 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 };
2316 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2319 pub extern "C" fn RawBolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::PayeePubKey {
2320 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2321 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 };
2326 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2329 pub extern "C" fn RawBolt11Invoice_description_hash(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Sha256 {
2330 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.description_hash();
2331 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 };
2336 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2339 pub extern "C" fn RawBolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::ExpiryTime {
2340 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2341 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 };
2346 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2349 pub extern "C" fn RawBolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::MinFinalCltvExpiryDelta {
2350 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2351 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 };
2357 pub extern "C" fn RawBolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_ThirtyTwoBytesZ {
2358 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2359 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 } }) };
2365 pub extern "C" fn RawBolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2366 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2367 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() }) };
2372 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2375 pub extern "C" fn RawBolt11Invoice_features(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
2376 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2377 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 };
2383 pub extern "C" fn RawBolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2384 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2385 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 } }); };
2389 /// Returns `None` if no amount is set or on overflow.
2392 pub extern "C" fn RawBolt11Invoice_amount_pico_btc(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2393 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_pico_btc();
2394 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() }) };
2400 pub extern "C" fn RawBolt11Invoice_currency(this_arg: &crate::lightning_invoice::RawBolt11Invoice) -> crate::lightning_invoice::Currency {
2401 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2402 crate::lightning_invoice::Currency::native_into(ret)
2405 /// Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`.
2407 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2410 pub extern "C" fn PositiveTimestamp_from_unix_timestamp(mut unix_seconds: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2411 let mut ret = lightning_invoice::PositiveTimestamp::from_unix_timestamp(unix_seconds);
2412 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() };
2416 /// Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in
2417 /// the range `0..=MAX_TIMESTAMP`.
2419 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2421 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2424 pub extern "C" fn PositiveTimestamp_from_system_time(mut time: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2425 let mut ret = lightning_invoice::PositiveTimestamp::from_system_time((::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(time)));
2426 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() };
2430 /// Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range
2431 /// `0..=MAX_TIMESTAMP`.
2433 /// Note that the subsecond part is dropped as it is not representable in BOLT 11 invoices.
2435 /// Otherwise, returns a [`CreationError::TimestampOutOfBounds`].
2438 pub extern "C" fn PositiveTimestamp_from_duration_since_epoch(mut duration: u64) -> crate::c_types::derived::CResult_PositiveTimestampCreationErrorZ {
2439 let mut ret = lightning_invoice::PositiveTimestamp::from_duration_since_epoch(core::time::Duration::from_secs(duration));
2440 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() };
2444 /// Returns the Unix timestamp representing the stored time
2447 pub extern "C" fn PositiveTimestamp_as_unix_timestamp(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2448 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_unix_timestamp();
2452 /// Returns the duration of the stored time since the Unix epoch
2455 pub extern "C" fn PositiveTimestamp_as_duration_since_epoch(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2456 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration_since_epoch();
2460 /// Returns the [`SystemTime`] representing the stored time
2463 pub extern "C" fn PositiveTimestamp_as_time(this_arg: &crate::lightning_invoice::PositiveTimestamp) -> u64 {
2464 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_time();
2465 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2468 /// The hash of the [`RawBolt11Invoice`] that was signed.
2471 pub extern "C" fn Bolt11Invoice_signable_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::ThirtyTwoBytes {
2472 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.signable_hash();
2473 crate::c_types::ThirtyTwoBytes { data: ret }
2476 /// Transform the `Bolt11Invoice` into its unchecked version.
2479 pub extern "C" fn Bolt11Invoice_into_signed_raw(mut this_arg: crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::SignedRawBolt11Invoice {
2480 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_signed_raw();
2481 crate::lightning_invoice::SignedRawBolt11Invoice { inner: ObjOps::heap_alloc(ret), is_owned: true }
2484 /// Check that the invoice is signed correctly and that key recovery works
2487 pub extern "C" fn Bolt11Invoice_check_signature(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CResult_NoneBolt11SemanticErrorZ {
2488 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.check_signature();
2489 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() };
2493 /// Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
2495 /// use lightning_invoice::*;
2497 /// let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
2498 /// h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
2499 /// 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
2500 /// h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
2501 /// j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
2502 /// ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
2503 /// guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
2504 /// ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
2505 /// p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
2506 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
2507 /// j5r6drg6k6zcqj0fcwg\";
2509 /// let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
2511 /// assert!(Bolt11Invoice::from_signed(signed).is_ok());
2515 pub extern "C" fn Bolt11Invoice_from_signed(mut signed_invoice: crate::lightning_invoice::SignedRawBolt11Invoice) -> crate::c_types::derived::CResult_Bolt11InvoiceBolt11SemanticErrorZ {
2516 let mut ret = lightning_invoice::Bolt11Invoice::from_signed(*unsafe { Box::from_raw(signed_invoice.take_inner()) });
2517 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() };
2521 /// Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
2524 pub extern "C" fn Bolt11Invoice_timestamp(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2525 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.timestamp();
2526 ret.duration_since(::std::time::SystemTime::UNIX_EPOCH).expect("Times must be post-1970").as_secs()
2529 /// Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
2532 pub extern "C" fn Bolt11Invoice_duration_since_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2533 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_since_epoch();
2537 /// Returns the hash to which we will receive the preimage on completion of the payment
2540 pub extern "C" fn Bolt11Invoice_payment_hash(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
2541 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_hash();
2545 /// Get the payee's public key if one was included in the invoice
2547 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2550 pub extern "C" fn Bolt11Invoice_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2551 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payee_pub_key();
2552 let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } };
2556 /// Get the payment secret if one was included in the invoice
2559 pub extern "C" fn Bolt11Invoice_payment_secret(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> *const [u8; 32] {
2560 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_secret();
2564 /// Get the payment metadata blob if one was included in the invoice
2567 pub extern "C" fn Bolt11Invoice_payment_metadata(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_CVec_u8ZZ {
2568 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.payment_metadata();
2569 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() }) };
2573 /// Get the invoice features if they were included in the invoice
2575 /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
2578 pub extern "C" fn Bolt11Invoice_features(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning::ln::features::Bolt11InvoiceFeatures {
2579 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.features();
2580 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 };
2584 /// Recover the payee's public key (only to be used if none was included in the invoice)
2587 pub extern "C" fn Bolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2588 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.recover_payee_pub_key();
2589 crate::c_types::PublicKey::from_rust(&ret)
2592 /// Recover the payee's public key if one was included in the invoice, otherwise return the
2593 /// recovered public key from the signature
2596 pub extern "C" fn Bolt11Invoice_get_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey {
2597 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_payee_pub_key();
2598 crate::c_types::PublicKey::from_rust(&ret)
2601 /// Returns the Duration since the Unix epoch at which the invoice expires.
2602 /// Returning None if overflow occurred.
2605 pub extern "C" fn Bolt11Invoice_expires_at(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2606 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expires_at();
2607 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() }) };
2611 /// Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
2614 pub extern "C" fn Bolt11Invoice_expiry_time(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2615 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiry_time();
2619 /// Returns whether the invoice has expired.
2622 pub extern "C" fn Bolt11Invoice_is_expired(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> bool {
2623 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.is_expired();
2627 /// Returns the Duration remaining until the invoice expires.
2630 pub extern "C" fn Bolt11Invoice_duration_until_expiry(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2631 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.duration_until_expiry();
2635 /// Returns the Duration remaining until the invoice expires given the current time.
2636 /// `time` is the timestamp as a duration since the Unix epoch.
2639 pub extern "C" fn Bolt11Invoice_expiration_remaining_from_epoch(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut time: u64) -> u64 {
2640 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.expiration_remaining_from_epoch(core::time::Duration::from_secs(time));
2644 /// Returns whether the expiry time would pass at the given point in time.
2645 /// `at_time` is the timestamp as a duration since the Unix epoch.
2648 pub extern "C" fn Bolt11Invoice_would_expire(this_arg: &crate::lightning_invoice::Bolt11Invoice, mut at_time: u64) -> bool {
2649 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.would_expire(core::time::Duration::from_secs(at_time));
2653 /// Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
2654 /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
2657 pub extern "C" fn Bolt11Invoice_min_final_cltv_expiry_delta(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> u64 {
2658 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.min_final_cltv_expiry_delta();
2662 /// Returns a list of all fallback addresses as [`Address`]es
2665 pub extern "C" fn Bolt11Invoice_fallback_addresses(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_StrZ {
2666 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.fallback_addresses();
2667 let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { alloc::string::ToString::to_string(&item).into() }); };
2671 /// Returns a list of all routes included in the invoice
2674 pub extern "C" fn Bolt11Invoice_private_routes(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_PrivateRouteZ {
2675 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.private_routes();
2676 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 } }); };
2680 /// Returns a list of all routes included in the invoice as the underlying hints
2683 pub extern "C" fn Bolt11Invoice_route_hints(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::CVec_RouteHintZ {
2684 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.route_hints();
2685 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 } }); };
2689 /// Returns the currency for which the invoice was issued
2692 pub extern "C" fn Bolt11Invoice_currency(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::lightning_invoice::Currency {
2693 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.currency();
2694 crate::lightning_invoice::Currency::native_into(ret)
2697 /// Returns the amount if specified in the invoice as millisatoshis.
2700 pub extern "C" fn Bolt11Invoice_amount_milli_satoshis(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::derived::COption_u64Z {
2701 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.amount_milli_satoshis();
2702 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() }) };
2706 /// Creates a new `Description` if `description` is at most 1023 __bytes__ long,
2707 /// returns [`CreationError::DescriptionTooLong`] otherwise
2709 /// Please note that single characters may use more than one byte due to UTF8 encoding.
2712 pub extern "C" fn Description_new(mut description: crate::c_types::Str) -> crate::c_types::derived::CResult_DescriptionCreationErrorZ {
2713 let mut ret = lightning_invoice::Description::new(description.into_string());
2714 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() };
2718 /// Returns the underlying description [`UntrustedString`]
2721 pub extern "C" fn Description_into_inner(mut this_arg: crate::lightning_invoice::Description) -> crate::lightning::util::string::UntrustedString {
2722 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2723 crate::lightning::util::string::UntrustedString { inner: ObjOps::heap_alloc(ret), is_owned: true }
2727 /// Get the string representation of a Description object
2728 pub extern "C" fn Description_to_str(o: &crate::lightning_invoice::Description) -> Str {
2729 alloc::format!("{}", o.get_native_ref()).into()
2731 /// Construct an `ExpiryTime` from seconds.
2734 pub extern "C" fn ExpiryTime_from_seconds(mut seconds: u64) -> crate::lightning_invoice::ExpiryTime {
2735 let mut ret = lightning_invoice::ExpiryTime::from_seconds(seconds);
2736 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2739 /// Construct an `ExpiryTime` from a [`Duration`], dropping the sub-second part.
2742 pub extern "C" fn ExpiryTime_from_duration(mut duration: u64) -> crate::lightning_invoice::ExpiryTime {
2743 let mut ret = lightning_invoice::ExpiryTime::from_duration(core::time::Duration::from_secs(duration));
2744 crate::lightning_invoice::ExpiryTime { inner: ObjOps::heap_alloc(ret), is_owned: true }
2747 /// Returns the expiry time in seconds
2750 pub extern "C" fn ExpiryTime_as_seconds(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2751 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_seconds();
2755 /// Returns a reference to the underlying [`Duration`] (=expiry time)
2758 pub extern "C" fn ExpiryTime_as_duration(this_arg: &crate::lightning_invoice::ExpiryTime) -> u64 {
2759 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_duration();
2763 /// Creates a new (partial) route from a list of hops
2766 pub extern "C" fn PrivateRoute_new(mut hops: crate::lightning::routing::router::RouteHint) -> crate::c_types::derived::CResult_PrivateRouteCreationErrorZ {
2767 let mut ret = lightning_invoice::PrivateRoute::new(*unsafe { Box::from_raw(hops.take_inner()) });
2768 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() };
2772 /// Returns the underlying list of hops
2775 pub extern "C" fn PrivateRoute_into_inner(mut this_arg: crate::lightning_invoice::PrivateRoute) -> crate::lightning::routing::router::RouteHint {
2776 let mut ret = (*unsafe { Box::from_raw(this_arg.take_inner()) }).into_inner();
2777 crate::lightning::routing::router::RouteHint { inner: ObjOps::heap_alloc(ret), is_owned: true }
2780 /// Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`]
2784 pub enum CreationError {
2785 /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
2787 /// The specified route has too many hops and can't be encoded
2789 /// The Unix timestamp of the supplied date is less than zero or greater than 35-bits
2790 TimestampOutOfBounds,
2791 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
2793 /// Route hints were required for this invoice and were missing. Applies to
2794 /// [phantom invoices].
2796 /// [phantom invoices]: crate::utils::create_phantom_invoice
2798 /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
2800 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
2801 MinFinalCltvExpiryDeltaTooShort,
2803 use lightning_invoice::CreationError as CreationErrorImport;
2804 pub(crate) type nativeCreationError = CreationErrorImport;
2806 impl CreationError {
2808 pub(crate) fn to_native(&self) -> nativeCreationError {
2810 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2811 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2812 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2813 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2814 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2815 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2819 pub(crate) fn into_native(self) -> nativeCreationError {
2821 CreationError::DescriptionTooLong => nativeCreationError::DescriptionTooLong,
2822 CreationError::RouteTooLong => nativeCreationError::RouteTooLong,
2823 CreationError::TimestampOutOfBounds => nativeCreationError::TimestampOutOfBounds,
2824 CreationError::InvalidAmount => nativeCreationError::InvalidAmount,
2825 CreationError::MissingRouteHints => nativeCreationError::MissingRouteHints,
2826 CreationError::MinFinalCltvExpiryDeltaTooShort => nativeCreationError::MinFinalCltvExpiryDeltaTooShort,
2830 pub(crate) fn from_native(native: &CreationErrorImport) -> Self {
2831 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeCreationError) };
2833 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2834 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2835 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2836 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2837 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2838 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2842 pub(crate) fn native_into(native: nativeCreationError) -> Self {
2844 nativeCreationError::DescriptionTooLong => CreationError::DescriptionTooLong,
2845 nativeCreationError::RouteTooLong => CreationError::RouteTooLong,
2846 nativeCreationError::TimestampOutOfBounds => CreationError::TimestampOutOfBounds,
2847 nativeCreationError::InvalidAmount => CreationError::InvalidAmount,
2848 nativeCreationError::MissingRouteHints => CreationError::MissingRouteHints,
2849 nativeCreationError::MinFinalCltvExpiryDeltaTooShort => CreationError::MinFinalCltvExpiryDeltaTooShort,
2853 /// Creates a copy of the CreationError
2855 pub extern "C" fn CreationError_clone(orig: &CreationError) -> CreationError {
2859 /// Used only if an object of this type is returned as a trait impl by a method
2860 pub(crate) extern "C" fn CreationError_clone_void(this_ptr: *const c_void) -> *mut c_void {
2861 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const CreationError)).clone() })) as *mut c_void
2864 /// Used only if an object of this type is returned as a trait impl by a method
2865 pub(crate) extern "C" fn CreationError_free_void(this_ptr: *mut c_void) {
2866 let _ = unsafe { Box::from_raw(this_ptr as *mut CreationError) };
2869 /// Utility method to constructs a new DescriptionTooLong-variant CreationError
2870 pub extern "C" fn CreationError_description_too_long() -> CreationError {
2871 CreationError::DescriptionTooLong}
2873 /// Utility method to constructs a new RouteTooLong-variant CreationError
2874 pub extern "C" fn CreationError_route_too_long() -> CreationError {
2875 CreationError::RouteTooLong}
2877 /// Utility method to constructs a new TimestampOutOfBounds-variant CreationError
2878 pub extern "C" fn CreationError_timestamp_out_of_bounds() -> CreationError {
2879 CreationError::TimestampOutOfBounds}
2881 /// Utility method to constructs a new InvalidAmount-variant CreationError
2882 pub extern "C" fn CreationError_invalid_amount() -> CreationError {
2883 CreationError::InvalidAmount}
2885 /// Utility method to constructs a new MissingRouteHints-variant CreationError
2886 pub extern "C" fn CreationError_missing_route_hints() -> CreationError {
2887 CreationError::MissingRouteHints}
2889 /// Utility method to constructs a new MinFinalCltvExpiryDeltaTooShort-variant CreationError
2890 pub extern "C" fn CreationError_min_final_cltv_expiry_delta_too_short() -> CreationError {
2891 CreationError::MinFinalCltvExpiryDeltaTooShort}
2892 /// Checks if two CreationErrors contain equal inner contents.
2893 /// This ignores pointers and is_owned flags and looks at the values in fields.
2895 pub extern "C" fn CreationError_eq(a: &CreationError, b: &CreationError) -> bool {
2896 if &a.to_native() == &b.to_native() { true } else { false }
2898 /// Get a string which allows debug introspection of a CreationError object
2899 pub extern "C" fn CreationError_debug_str_void(o: *const c_void) -> Str {
2900 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::CreationError }).into()}
2902 /// Get the string representation of a CreationError object
2903 pub extern "C" fn CreationError_to_str(o: &crate::lightning_invoice::CreationError) -> Str {
2904 alloc::format!("{}", &o.to_native()).into()
2906 /// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
2907 /// the requirements sections in BOLT #11
2911 pub enum Bolt11SemanticError {
2912 /// The invoice is missing the mandatory payment hash
2914 /// The invoice has multiple payment hashes which isn't allowed
2915 MultiplePaymentHashes,
2916 /// No description or description hash are part of the invoice
2918 /// The invoice contains multiple descriptions and/or description hashes which isn't allowed
2919 MultipleDescriptions,
2920 /// The invoice is missing the mandatory payment secret, which all modern lightning nodes
2923 /// The invoice contains multiple payment secrets
2924 MultiplePaymentSecrets,
2925 /// The invoice's features are invalid
2927 /// The recovery id doesn't fit the signature/pub key
2929 /// The invoice's signature is invalid
2931 /// The invoice's amount was not a whole number of millisatoshis
2934 use lightning_invoice::Bolt11SemanticError as Bolt11SemanticErrorImport;
2935 pub(crate) type nativeBolt11SemanticError = Bolt11SemanticErrorImport;
2937 impl Bolt11SemanticError {
2939 pub(crate) fn to_native(&self) -> nativeBolt11SemanticError {
2941 Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
2942 Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
2943 Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
2944 Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
2945 Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
2946 Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
2947 Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
2948 Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
2949 Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
2950 Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
2954 pub(crate) fn into_native(self) -> nativeBolt11SemanticError {
2956 Bolt11SemanticError::NoPaymentHash => nativeBolt11SemanticError::NoPaymentHash,
2957 Bolt11SemanticError::MultiplePaymentHashes => nativeBolt11SemanticError::MultiplePaymentHashes,
2958 Bolt11SemanticError::NoDescription => nativeBolt11SemanticError::NoDescription,
2959 Bolt11SemanticError::MultipleDescriptions => nativeBolt11SemanticError::MultipleDescriptions,
2960 Bolt11SemanticError::NoPaymentSecret => nativeBolt11SemanticError::NoPaymentSecret,
2961 Bolt11SemanticError::MultiplePaymentSecrets => nativeBolt11SemanticError::MultiplePaymentSecrets,
2962 Bolt11SemanticError::InvalidFeatures => nativeBolt11SemanticError::InvalidFeatures,
2963 Bolt11SemanticError::InvalidRecoveryId => nativeBolt11SemanticError::InvalidRecoveryId,
2964 Bolt11SemanticError::InvalidSignature => nativeBolt11SemanticError::InvalidSignature,
2965 Bolt11SemanticError::ImpreciseAmount => nativeBolt11SemanticError::ImpreciseAmount,
2969 pub(crate) fn from_native(native: &Bolt11SemanticErrorImport) -> Self {
2970 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeBolt11SemanticError) };
2972 nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
2973 nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
2974 nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
2975 nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
2976 nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
2977 nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
2978 nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
2979 nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
2980 nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
2981 nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
2985 pub(crate) fn native_into(native: nativeBolt11SemanticError) -> Self {
2987 nativeBolt11SemanticError::NoPaymentHash => Bolt11SemanticError::NoPaymentHash,
2988 nativeBolt11SemanticError::MultiplePaymentHashes => Bolt11SemanticError::MultiplePaymentHashes,
2989 nativeBolt11SemanticError::NoDescription => Bolt11SemanticError::NoDescription,
2990 nativeBolt11SemanticError::MultipleDescriptions => Bolt11SemanticError::MultipleDescriptions,
2991 nativeBolt11SemanticError::NoPaymentSecret => Bolt11SemanticError::NoPaymentSecret,
2992 nativeBolt11SemanticError::MultiplePaymentSecrets => Bolt11SemanticError::MultiplePaymentSecrets,
2993 nativeBolt11SemanticError::InvalidFeatures => Bolt11SemanticError::InvalidFeatures,
2994 nativeBolt11SemanticError::InvalidRecoveryId => Bolt11SemanticError::InvalidRecoveryId,
2995 nativeBolt11SemanticError::InvalidSignature => Bolt11SemanticError::InvalidSignature,
2996 nativeBolt11SemanticError::ImpreciseAmount => Bolt11SemanticError::ImpreciseAmount,
3000 /// Creates a copy of the Bolt11SemanticError
3002 pub extern "C" fn Bolt11SemanticError_clone(orig: &Bolt11SemanticError) -> Bolt11SemanticError {
3006 /// Used only if an object of this type is returned as a trait impl by a method
3007 pub(crate) extern "C" fn Bolt11SemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void {
3008 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11SemanticError)).clone() })) as *mut c_void
3011 /// Used only if an object of this type is returned as a trait impl by a method
3012 pub(crate) extern "C" fn Bolt11SemanticError_free_void(this_ptr: *mut c_void) {
3013 let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11SemanticError) };
3016 /// Utility method to constructs a new NoPaymentHash-variant Bolt11SemanticError
3017 pub extern "C" fn Bolt11SemanticError_no_payment_hash() -> Bolt11SemanticError {
3018 Bolt11SemanticError::NoPaymentHash}
3020 /// Utility method to constructs a new MultiplePaymentHashes-variant Bolt11SemanticError
3021 pub extern "C" fn Bolt11SemanticError_multiple_payment_hashes() -> Bolt11SemanticError {
3022 Bolt11SemanticError::MultiplePaymentHashes}
3024 /// Utility method to constructs a new NoDescription-variant Bolt11SemanticError
3025 pub extern "C" fn Bolt11SemanticError_no_description() -> Bolt11SemanticError {
3026 Bolt11SemanticError::NoDescription}
3028 /// Utility method to constructs a new MultipleDescriptions-variant Bolt11SemanticError
3029 pub extern "C" fn Bolt11SemanticError_multiple_descriptions() -> Bolt11SemanticError {
3030 Bolt11SemanticError::MultipleDescriptions}
3032 /// Utility method to constructs a new NoPaymentSecret-variant Bolt11SemanticError
3033 pub extern "C" fn Bolt11SemanticError_no_payment_secret() -> Bolt11SemanticError {
3034 Bolt11SemanticError::NoPaymentSecret}
3036 /// Utility method to constructs a new MultiplePaymentSecrets-variant Bolt11SemanticError
3037 pub extern "C" fn Bolt11SemanticError_multiple_payment_secrets() -> Bolt11SemanticError {
3038 Bolt11SemanticError::MultiplePaymentSecrets}
3040 /// Utility method to constructs a new InvalidFeatures-variant Bolt11SemanticError
3041 pub extern "C" fn Bolt11SemanticError_invalid_features() -> Bolt11SemanticError {
3042 Bolt11SemanticError::InvalidFeatures}
3044 /// Utility method to constructs a new InvalidRecoveryId-variant Bolt11SemanticError
3045 pub extern "C" fn Bolt11SemanticError_invalid_recovery_id() -> Bolt11SemanticError {
3046 Bolt11SemanticError::InvalidRecoveryId}
3048 /// Utility method to constructs a new InvalidSignature-variant Bolt11SemanticError
3049 pub extern "C" fn Bolt11SemanticError_invalid_signature() -> Bolt11SemanticError {
3050 Bolt11SemanticError::InvalidSignature}
3052 /// Utility method to constructs a new ImpreciseAmount-variant Bolt11SemanticError
3053 pub extern "C" fn Bolt11SemanticError_imprecise_amount() -> Bolt11SemanticError {
3054 Bolt11SemanticError::ImpreciseAmount}
3055 /// Checks if two Bolt11SemanticErrors contain equal inner contents.
3056 /// This ignores pointers and is_owned flags and looks at the values in fields.
3058 pub extern "C" fn Bolt11SemanticError_eq(a: &Bolt11SemanticError, b: &Bolt11SemanticError) -> bool {
3059 if &a.to_native() == &b.to_native() { true } else { false }
3061 /// Get a string which allows debug introspection of a Bolt11SemanticError object
3062 pub extern "C" fn Bolt11SemanticError_debug_str_void(o: *const c_void) -> Str {
3063 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::Bolt11SemanticError }).into()}
3065 /// Get the string representation of a Bolt11SemanticError object
3066 pub extern "C" fn Bolt11SemanticError_to_str(o: &crate::lightning_invoice::Bolt11SemanticError) -> Str {
3067 alloc::format!("{}", &o.to_native()).into()
3069 /// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
3074 pub enum SignOrCreationError {
3075 /// An error occurred during signing
3077 /// An error occurred while building the transaction
3079 crate::lightning_invoice::CreationError),
3081 use lightning_invoice::SignOrCreationError as SignOrCreationErrorImport;
3082 pub(crate) type nativeSignOrCreationError = SignOrCreationErrorImport<>;
3084 impl SignOrCreationError {
3086 pub(crate) fn to_native(&self) -> nativeSignOrCreationError {
3088 SignOrCreationError::SignError => {
3089 nativeSignOrCreationError::SignError (
3093 SignOrCreationError::CreationError (ref a, ) => {
3094 let mut a_nonref = Clone::clone(a);
3095 nativeSignOrCreationError::CreationError (
3096 a_nonref.into_native(),
3102 pub(crate) fn into_native(self) -> nativeSignOrCreationError {
3104 SignOrCreationError::SignError => {
3105 nativeSignOrCreationError::SignError (
3109 SignOrCreationError::CreationError (mut a, ) => {
3110 nativeSignOrCreationError::CreationError (
3117 pub(crate) fn from_native(native: &SignOrCreationErrorImport<>) -> Self {
3118 let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSignOrCreationError) };
3120 nativeSignOrCreationError::SignError (ref a, ) => {
3121 SignOrCreationError::SignError },
3122 nativeSignOrCreationError::CreationError (ref a, ) => {
3123 let mut a_nonref = Clone::clone(a);
3124 SignOrCreationError::CreationError (
3125 crate::lightning_invoice::CreationError::native_into(a_nonref),
3131 pub(crate) fn native_into(native: nativeSignOrCreationError) -> Self {
3133 nativeSignOrCreationError::SignError (mut a, ) => {
3134 SignOrCreationError::SignError },
3135 nativeSignOrCreationError::CreationError (mut a, ) => {
3136 SignOrCreationError::CreationError (
3137 crate::lightning_invoice::CreationError::native_into(a),
3143 /// Frees any resources used by the SignOrCreationError
3145 pub extern "C" fn SignOrCreationError_free(this_ptr: SignOrCreationError) { }
3146 /// Creates a copy of the SignOrCreationError
3148 pub extern "C" fn SignOrCreationError_clone(orig: &SignOrCreationError) -> SignOrCreationError {
3152 /// Used only if an object of this type is returned as a trait impl by a method
3153 pub(crate) extern "C" fn SignOrCreationError_clone_void(this_ptr: *const c_void) -> *mut c_void {
3154 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SignOrCreationError)).clone() })) as *mut c_void
3157 /// Used only if an object of this type is returned as a trait impl by a method
3158 pub(crate) extern "C" fn SignOrCreationError_free_void(this_ptr: *mut c_void) {
3159 let _ = unsafe { Box::from_raw(this_ptr as *mut SignOrCreationError) };
3162 /// Utility method to constructs a new SignError-variant SignOrCreationError
3163 pub extern "C" fn SignOrCreationError_sign_error() -> SignOrCreationError {
3164 SignOrCreationError::SignError
3167 /// Utility method to constructs a new CreationError-variant SignOrCreationError
3168 pub extern "C" fn SignOrCreationError_creation_error(a: crate::lightning_invoice::CreationError) -> SignOrCreationError {
3169 SignOrCreationError::CreationError(a, )
3171 /// Checks if two SignOrCreationErrors contain equal inner contents.
3172 /// This ignores pointers and is_owned flags and looks at the values in fields.
3174 pub extern "C" fn SignOrCreationError_eq(a: &SignOrCreationError, b: &SignOrCreationError) -> bool {
3175 if &a.to_native() == &b.to_native() { true } else { false }
3177 /// Get a string which allows debug introspection of a SignOrCreationError object
3178 pub extern "C" fn SignOrCreationError_debug_str_void(o: *const c_void) -> Str {
3179 alloc::format!("{:?}", unsafe { o as *const crate::lightning_invoice::SignOrCreationError }).into()}
3181 /// Get the string representation of a SignOrCreationError object
3182 pub extern "C" fn SignOrCreationError_to_str(o: &crate::lightning_invoice::SignOrCreationError) -> Str {
3183 alloc::format!("{}", &o.to_native()).into()