+mod prelude {
+
+use alloc::str::FromStr;
+use alloc::string::String;
+use core::ffi::c_void;
+use core::convert::Infallible;
+use bitcoin::hashes::Hash;
+use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
+
+}
+mod sync {
+
+use alloc::str::FromStr;
+use alloc::string::String;
+use core::ffi::c_void;
+use core::convert::Infallible;
+use bitcoin::hashes::Hash;
+use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
+
+}
+/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
+/// reasons, but should generally result in an \"invalid BOLT11 invoice\" message for the user.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum Bolt11ParseError {
+ Bech32Error(
+ crate::c_types::Bech32Error),
+ ParseAmountError(
+ crate::c_types::Error),
+ MalformedSignature(
+ crate::c_types::Secp256k1Error),
+ BadPrefix,
+ UnknownCurrency,
+ UnknownSiPrefix,
+ MalformedHRP,
+ TooShortDataPart,
+ UnexpectedEndOfTaggedFields,
+ DescriptionDecodeError(
+ crate::c_types::Error),
+ PaddingError,
+ IntegerOverflowError,
+ InvalidSegWitProgramLength,
+ InvalidPubKeyHashLength,
+ InvalidScriptHashLength,
+ InvalidRecoveryId,
+ InvalidSliceLength(
+ crate::c_types::Str),
+ /// Not an error, but used internally to signal that a part of the invoice should be ignored
+ /// according to BOLT11
+ Skip,
+}
+use lightning_invoice::Bolt11ParseError as Bolt11ParseErrorImport;
+pub(crate) type nativeBolt11ParseError = Bolt11ParseErrorImport;
+
+impl Bolt11ParseError {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeBolt11ParseError {
+ match self {
+ Bolt11ParseError::Bech32Error (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::Bech32Error (
+ a_nonref.into_rust(),
+ )
+ },
+ Bolt11ParseError::ParseAmountError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::ParseAmountError (
+ u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
+ )
+ },
+ Bolt11ParseError::MalformedSignature (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::MalformedSignature (
+ a_nonref.into_rust(),
+ )
+ },
+ Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
+ Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
+ Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
+ Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
+ Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
+ Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
+ Bolt11ParseError::DescriptionDecodeError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::DescriptionDecodeError (
+ core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
+ )
+ },
+ Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
+ Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
+ Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
+ Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
+ Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
+ Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
+ Bolt11ParseError::InvalidSliceLength (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeBolt11ParseError::InvalidSliceLength (
+ a_nonref.into_string(),
+ )
+ },
+ Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeBolt11ParseError {
+ match self {
+ Bolt11ParseError::Bech32Error (mut a, ) => {
+ nativeBolt11ParseError::Bech32Error (
+ a.into_rust(),
+ )
+ },
+ Bolt11ParseError::ParseAmountError (mut a, ) => {
+ nativeBolt11ParseError::ParseAmountError (
+ u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
+ )
+ },
+ Bolt11ParseError::MalformedSignature (mut a, ) => {
+ nativeBolt11ParseError::MalformedSignature (
+ a.into_rust(),
+ )
+ },
+ Bolt11ParseError::BadPrefix => nativeBolt11ParseError::BadPrefix,
+ Bolt11ParseError::UnknownCurrency => nativeBolt11ParseError::UnknownCurrency,
+ Bolt11ParseError::UnknownSiPrefix => nativeBolt11ParseError::UnknownSiPrefix,
+ Bolt11ParseError::MalformedHRP => nativeBolt11ParseError::MalformedHRP,
+ Bolt11ParseError::TooShortDataPart => nativeBolt11ParseError::TooShortDataPart,
+ Bolt11ParseError::UnexpectedEndOfTaggedFields => nativeBolt11ParseError::UnexpectedEndOfTaggedFields,
+ Bolt11ParseError::DescriptionDecodeError (mut a, ) => {
+ nativeBolt11ParseError::DescriptionDecodeError (
+ core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
+ )
+ },
+ Bolt11ParseError::PaddingError => nativeBolt11ParseError::PaddingError,
+ Bolt11ParseError::IntegerOverflowError => nativeBolt11ParseError::IntegerOverflowError,
+ Bolt11ParseError::InvalidSegWitProgramLength => nativeBolt11ParseError::InvalidSegWitProgramLength,
+ Bolt11ParseError::InvalidPubKeyHashLength => nativeBolt11ParseError::InvalidPubKeyHashLength,
+ Bolt11ParseError::InvalidScriptHashLength => nativeBolt11ParseError::InvalidScriptHashLength,
+ Bolt11ParseError::InvalidRecoveryId => nativeBolt11ParseError::InvalidRecoveryId,
+ Bolt11ParseError::InvalidSliceLength (mut a, ) => {
+ nativeBolt11ParseError::InvalidSliceLength (
+ a.into_string(),
+ )
+ },
+ Bolt11ParseError::Skip => nativeBolt11ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeBolt11ParseError) -> Self {
+ match native {
+ nativeBolt11ParseError::Bech32Error (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::Bech32Error (
+ crate::c_types::Bech32Error::from_rust(a_nonref),
+ )
+ },
+ nativeBolt11ParseError::ParseAmountError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::ParseAmountError (
+ crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
+ )
+ },
+ nativeBolt11ParseError::MalformedSignature (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::MalformedSignature (
+ crate::c_types::Secp256k1Error::from_rust(a_nonref),
+ )
+ },
+ nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
+ nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
+ nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
+ nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
+ nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
+ nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
+ nativeBolt11ParseError::DescriptionDecodeError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::DescriptionDecodeError (
+ crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
+ )
+ },
+ nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
+ nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
+ nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
+ nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
+ nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
+ nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
+ nativeBolt11ParseError::InvalidSliceLength (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ Bolt11ParseError::InvalidSliceLength (
+ a_nonref.into(),
+ )
+ },
+ nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeBolt11ParseError) -> Self {
+ match native {
+ nativeBolt11ParseError::Bech32Error (mut a, ) => {
+ Bolt11ParseError::Bech32Error (
+ crate::c_types::Bech32Error::from_rust(a),
+ )
+ },
+ nativeBolt11ParseError::ParseAmountError (mut a, ) => {
+ Bolt11ParseError::ParseAmountError (
+ crate::c_types::Error { _dummy: 0 } /*a*/,
+ )
+ },
+ nativeBolt11ParseError::MalformedSignature (mut a, ) => {
+ Bolt11ParseError::MalformedSignature (
+ crate::c_types::Secp256k1Error::from_rust(a),
+ )
+ },
+ nativeBolt11ParseError::BadPrefix => Bolt11ParseError::BadPrefix,
+ nativeBolt11ParseError::UnknownCurrency => Bolt11ParseError::UnknownCurrency,
+ nativeBolt11ParseError::UnknownSiPrefix => Bolt11ParseError::UnknownSiPrefix,
+ nativeBolt11ParseError::MalformedHRP => Bolt11ParseError::MalformedHRP,
+ nativeBolt11ParseError::TooShortDataPart => Bolt11ParseError::TooShortDataPart,
+ nativeBolt11ParseError::UnexpectedEndOfTaggedFields => Bolt11ParseError::UnexpectedEndOfTaggedFields,
+ nativeBolt11ParseError::DescriptionDecodeError (mut a, ) => {
+ Bolt11ParseError::DescriptionDecodeError (
+ crate::c_types::Error { _dummy: 0 } /*a*/,
+ )
+ },
+ nativeBolt11ParseError::PaddingError => Bolt11ParseError::PaddingError,
+ nativeBolt11ParseError::IntegerOverflowError => Bolt11ParseError::IntegerOverflowError,
+ nativeBolt11ParseError::InvalidSegWitProgramLength => Bolt11ParseError::InvalidSegWitProgramLength,
+ nativeBolt11ParseError::InvalidPubKeyHashLength => Bolt11ParseError::InvalidPubKeyHashLength,
+ nativeBolt11ParseError::InvalidScriptHashLength => Bolt11ParseError::InvalidScriptHashLength,
+ nativeBolt11ParseError::InvalidRecoveryId => Bolt11ParseError::InvalidRecoveryId,
+ nativeBolt11ParseError::InvalidSliceLength (mut a, ) => {
+ Bolt11ParseError::InvalidSliceLength (
+ a.into(),
+ )
+ },
+ nativeBolt11ParseError::Skip => Bolt11ParseError::Skip,
+ }
+ }
+}
+/// Frees any resources used by the Bolt11ParseError
+#[no_mangle]
+pub extern "C" fn Bolt11ParseError_free(this_ptr: Bolt11ParseError) { }
+/// Creates a copy of the Bolt11ParseError
+#[no_mangle]
+pub extern "C" fn Bolt11ParseError_clone(orig: &Bolt11ParseError) -> Bolt11ParseError {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Bolt11ParseError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const Bolt11ParseError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn Bolt11ParseError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut Bolt11ParseError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new Bech32Error-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_bech32_error(a: crate::c_types::Bech32Error) -> Bolt11ParseError {
+ Bolt11ParseError::Bech32Error(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new ParseAmountError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_parse_amount_error(a: crate::c_types::Error) -> Bolt11ParseError {
+ Bolt11ParseError::ParseAmountError(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new MalformedSignature-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> Bolt11ParseError {
+ Bolt11ParseError::MalformedSignature(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new BadPrefix-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_bad_prefix() -> Bolt11ParseError {
+ Bolt11ParseError::BadPrefix}
+#[no_mangle]
+/// Utility method to constructs a new UnknownCurrency-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_unknown_currency() -> Bolt11ParseError {
+ Bolt11ParseError::UnknownCurrency}
+#[no_mangle]
+/// Utility method to constructs a new UnknownSiPrefix-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_unknown_si_prefix() -> Bolt11ParseError {
+ Bolt11ParseError::UnknownSiPrefix}
+#[no_mangle]
+/// Utility method to constructs a new MalformedHRP-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_malformed_hrp() -> Bolt11ParseError {
+ Bolt11ParseError::MalformedHRP}
+#[no_mangle]
+/// Utility method to constructs a new TooShortDataPart-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_too_short_data_part() -> Bolt11ParseError {
+ Bolt11ParseError::TooShortDataPart}
+#[no_mangle]
+/// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_unexpected_end_of_tagged_fields() -> Bolt11ParseError {
+ Bolt11ParseError::UnexpectedEndOfTaggedFields}
+#[no_mangle]
+/// Utility method to constructs a new DescriptionDecodeError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_description_decode_error(a: crate::c_types::Error) -> Bolt11ParseError {
+ Bolt11ParseError::DescriptionDecodeError(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new PaddingError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_padding_error() -> Bolt11ParseError {
+ Bolt11ParseError::PaddingError}
+#[no_mangle]
+/// Utility method to constructs a new IntegerOverflowError-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_integer_overflow_error() -> Bolt11ParseError {
+ Bolt11ParseError::IntegerOverflowError}
+#[no_mangle]
+/// Utility method to constructs a new InvalidSegWitProgramLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_seg_wit_program_length() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidSegWitProgramLength}
+#[no_mangle]
+/// Utility method to constructs a new InvalidPubKeyHashLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_pub_key_hash_length() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidPubKeyHashLength}
+#[no_mangle]
+/// Utility method to constructs a new InvalidScriptHashLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_script_hash_length() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidScriptHashLength}
+#[no_mangle]
+/// Utility method to constructs a new InvalidRecoveryId-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_recovery_id() -> Bolt11ParseError {
+ Bolt11ParseError::InvalidRecoveryId}
+#[no_mangle]
+/// Utility method to constructs a new InvalidSliceLength-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_invalid_slice_length(a: crate::c_types::Str) -> Bolt11ParseError {
+ Bolt11ParseError::InvalidSliceLength(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new Skip-variant Bolt11ParseError
+pub extern "C" fn Bolt11ParseError_skip() -> Bolt11ParseError {
+ Bolt11ParseError::Skip}
+/// Checks if two Bolt11ParseErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn Bolt11ParseError_eq(a: &Bolt11ParseError, b: &Bolt11ParseError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
+/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
+/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum ParseOrSemanticError {
+ /// The invoice couldn't be decoded
+ ParseError(
+ crate::lightning_invoice::Bolt11ParseError),
+ /// The invoice could be decoded but violates the BOLT11 standard
+ SemanticError(
+ crate::lightning_invoice::Bolt11SemanticError),
+}
+use lightning_invoice::ParseOrSemanticError as ParseOrSemanticErrorImport;
+pub(crate) type nativeParseOrSemanticError = ParseOrSemanticErrorImport;
+
+impl ParseOrSemanticError {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeParseOrSemanticError {
+ match self {
+ ParseOrSemanticError::ParseError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseOrSemanticError::ParseError (
+ a_nonref.into_native(),
+ )
+ },
+ ParseOrSemanticError::SemanticError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseOrSemanticError::SemanticError (
+ a_nonref.into_native(),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeParseOrSemanticError {
+ match self {
+ ParseOrSemanticError::ParseError (mut a, ) => {
+ nativeParseOrSemanticError::ParseError (
+ a.into_native(),
+ )
+ },
+ ParseOrSemanticError::SemanticError (mut a, ) => {
+ nativeParseOrSemanticError::SemanticError (
+ a.into_native(),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeParseOrSemanticError) -> Self {
+ match native {
+ nativeParseOrSemanticError::ParseError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseOrSemanticError::ParseError (
+ crate::lightning_invoice::Bolt11ParseError::native_into(a_nonref),
+ )
+ },
+ nativeParseOrSemanticError::SemanticError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseOrSemanticError::SemanticError (
+ crate::lightning_invoice::Bolt11SemanticError::native_into(a_nonref),
+ )
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeParseOrSemanticError) -> Self {
+ match native {
+ nativeParseOrSemanticError::ParseError (mut a, ) => {
+ ParseOrSemanticError::ParseError (
+ crate::lightning_invoice::Bolt11ParseError::native_into(a),
+ )
+ },
+ nativeParseOrSemanticError::SemanticError (mut a, ) => {
+ ParseOrSemanticError::SemanticError (
+ crate::lightning_invoice::Bolt11SemanticError::native_into(a),
+ )
+ },
+ }
+ }
+}
+/// Frees any resources used by the ParseOrSemanticError
+#[no_mangle]
+pub extern "C" fn ParseOrSemanticError_free(this_ptr: ParseOrSemanticError) { }
+/// Creates a copy of the ParseOrSemanticError
+#[no_mangle]
+pub extern "C" fn ParseOrSemanticError_clone(orig: &ParseOrSemanticError) -> ParseOrSemanticError {
+ orig.clone()
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn ParseOrSemanticError_clone_void(this_ptr: *const c_void) -> *mut c_void {
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ParseOrSemanticError)).clone() })) as *mut c_void
+}
+#[allow(unused)]
+/// Used only if an object of this type is returned as a trait impl by a method
+pub(crate) extern "C" fn ParseOrSemanticError_free_void(this_ptr: *mut c_void) {
+ let _ = unsafe { Box::from_raw(this_ptr as *mut ParseOrSemanticError) };
+}
+#[no_mangle]
+/// Utility method to constructs a new ParseError-variant ParseOrSemanticError
+pub extern "C" fn ParseOrSemanticError_parse_error(a: crate::lightning_invoice::Bolt11ParseError) -> ParseOrSemanticError {
+ ParseOrSemanticError::ParseError(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new SemanticError-variant ParseOrSemanticError
+pub extern "C" fn ParseOrSemanticError_semantic_error(a: crate::lightning_invoice::Bolt11SemanticError) -> ParseOrSemanticError {
+ ParseOrSemanticError::SemanticError(a, )
+}
+/// Checks if two ParseOrSemanticErrors contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ParseOrSemanticError_eq(a: &ParseOrSemanticError, b: &ParseOrSemanticError) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+/// The maximum timestamp as [`Duration::as_secs`] since the Unix epoch allowed by [`BOLT 11`].