+use alloc::str::FromStr;
+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 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 ParseError {
+ 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::ParseError as ParseErrorImport;
+pub(crate) type nativeParseError = ParseErrorImport;
+
+impl ParseError {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeParseError {
+ match self {
+ ParseError::Bech32Error (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseError::Bech32Error (
+ a_nonref.into_rust(),
+ )
+ },
+ ParseError::ParseAmountError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseError::ParseAmountError (
+ u8::from_str_radix(" a", 10).unwrap_err() /*a_nonref*/,
+ )
+ },
+ ParseError::MalformedSignature (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseError::MalformedSignature (
+ a_nonref.into_rust(),
+ )
+ },
+ ParseError::BadPrefix => nativeParseError::BadPrefix,
+ ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
+ ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
+ ParseError::MalformedHRP => nativeParseError::MalformedHRP,
+ ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
+ ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
+ ParseError::DescriptionDecodeError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseError::DescriptionDecodeError (
+ core::str::from_utf8(&[0xff]).unwrap_err() /*a_nonref*/,
+ )
+ },
+ ParseError::PaddingError => nativeParseError::PaddingError,
+ ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
+ ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
+ ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
+ ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
+ ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
+ ParseError::InvalidSliceLength (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ nativeParseError::InvalidSliceLength (
+ a_nonref.into_string(),
+ )
+ },
+ ParseError::Skip => nativeParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeParseError {
+ match self {
+ ParseError::Bech32Error (mut a, ) => {
+ nativeParseError::Bech32Error (
+ a.into_rust(),
+ )
+ },
+ ParseError::ParseAmountError (mut a, ) => {
+ nativeParseError::ParseAmountError (
+ u8::from_str_radix(" a", 10).unwrap_err() /*a*/,
+ )
+ },
+ ParseError::MalformedSignature (mut a, ) => {
+ nativeParseError::MalformedSignature (
+ a.into_rust(),
+ )
+ },
+ ParseError::BadPrefix => nativeParseError::BadPrefix,
+ ParseError::UnknownCurrency => nativeParseError::UnknownCurrency,
+ ParseError::UnknownSiPrefix => nativeParseError::UnknownSiPrefix,
+ ParseError::MalformedHRP => nativeParseError::MalformedHRP,
+ ParseError::TooShortDataPart => nativeParseError::TooShortDataPart,
+ ParseError::UnexpectedEndOfTaggedFields => nativeParseError::UnexpectedEndOfTaggedFields,
+ ParseError::DescriptionDecodeError (mut a, ) => {
+ nativeParseError::DescriptionDecodeError (
+ core::str::from_utf8(&[0xff]).unwrap_err() /*a*/,
+ )
+ },
+ ParseError::PaddingError => nativeParseError::PaddingError,
+ ParseError::IntegerOverflowError => nativeParseError::IntegerOverflowError,
+ ParseError::InvalidSegWitProgramLength => nativeParseError::InvalidSegWitProgramLength,
+ ParseError::InvalidPubKeyHashLength => nativeParseError::InvalidPubKeyHashLength,
+ ParseError::InvalidScriptHashLength => nativeParseError::InvalidScriptHashLength,
+ ParseError::InvalidRecoveryId => nativeParseError::InvalidRecoveryId,
+ ParseError::InvalidSliceLength (mut a, ) => {
+ nativeParseError::InvalidSliceLength (
+ a.into_string(),
+ )
+ },
+ ParseError::Skip => nativeParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeParseError) -> Self {
+ match native {
+ nativeParseError::Bech32Error (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseError::Bech32Error (
+ crate::c_types::Bech32Error::from_rust(a_nonref),
+ )
+ },
+ nativeParseError::ParseAmountError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseError::ParseAmountError (
+ crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
+ )
+ },
+ nativeParseError::MalformedSignature (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseError::MalformedSignature (
+ crate::c_types::Secp256k1Error::from_rust(a_nonref),
+ )
+ },
+ nativeParseError::BadPrefix => ParseError::BadPrefix,
+ nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
+ nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
+ nativeParseError::MalformedHRP => ParseError::MalformedHRP,
+ nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
+ nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
+ nativeParseError::DescriptionDecodeError (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseError::DescriptionDecodeError (
+ crate::c_types::Error { _dummy: 0 } /*a_nonref*/,
+ )
+ },
+ nativeParseError::PaddingError => ParseError::PaddingError,
+ nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
+ nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
+ nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
+ nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
+ nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
+ nativeParseError::InvalidSliceLength (ref a, ) => {
+ let mut a_nonref = Clone::clone(a);
+ ParseError::InvalidSliceLength (
+ a_nonref.into(),
+ )
+ },
+ nativeParseError::Skip => ParseError::Skip,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeParseError) -> Self {
+ match native {
+ nativeParseError::Bech32Error (mut a, ) => {
+ ParseError::Bech32Error (
+ crate::c_types::Bech32Error::from_rust(a),
+ )
+ },
+ nativeParseError::ParseAmountError (mut a, ) => {
+ ParseError::ParseAmountError (
+ crate::c_types::Error { _dummy: 0 } /*a*/,
+ )
+ },
+ nativeParseError::MalformedSignature (mut a, ) => {
+ ParseError::MalformedSignature (
+ crate::c_types::Secp256k1Error::from_rust(a),
+ )
+ },
+ nativeParseError::BadPrefix => ParseError::BadPrefix,
+ nativeParseError::UnknownCurrency => ParseError::UnknownCurrency,
+ nativeParseError::UnknownSiPrefix => ParseError::UnknownSiPrefix,
+ nativeParseError::MalformedHRP => ParseError::MalformedHRP,
+ nativeParseError::TooShortDataPart => ParseError::TooShortDataPart,
+ nativeParseError::UnexpectedEndOfTaggedFields => ParseError::UnexpectedEndOfTaggedFields,
+ nativeParseError::DescriptionDecodeError (mut a, ) => {
+ ParseError::DescriptionDecodeError (
+ crate::c_types::Error { _dummy: 0 } /*a*/,
+ )
+ },
+ nativeParseError::PaddingError => ParseError::PaddingError,
+ nativeParseError::IntegerOverflowError => ParseError::IntegerOverflowError,
+ nativeParseError::InvalidSegWitProgramLength => ParseError::InvalidSegWitProgramLength,
+ nativeParseError::InvalidPubKeyHashLength => ParseError::InvalidPubKeyHashLength,
+ nativeParseError::InvalidScriptHashLength => ParseError::InvalidScriptHashLength,
+ nativeParseError::InvalidRecoveryId => ParseError::InvalidRecoveryId,
+ nativeParseError::InvalidSliceLength (mut a, ) => {
+ ParseError::InvalidSliceLength (
+ a.into(),
+ )
+ },
+ nativeParseError::Skip => ParseError::Skip,
+ }
+ }
+}
+/// Frees any resources used by the ParseError
+#[no_mangle]
+pub extern "C" fn ParseError_free(this_ptr: ParseError) { }
+/// Creates a copy of the ParseError
+#[no_mangle]
+pub extern "C" fn ParseError_clone(orig: &ParseError) -> ParseError {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new Bech32Error-variant ParseError
+pub extern "C" fn ParseError_bech32_error(a: crate::c_types::Bech32Error) -> ParseError {
+ ParseError::Bech32Error(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new ParseAmountError-variant ParseError
+pub extern "C" fn ParseError_parse_amount_error(a: crate::c_types::Error) -> ParseError {
+ ParseError::ParseAmountError(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new MalformedSignature-variant ParseError
+pub extern "C" fn ParseError_malformed_signature(a: crate::c_types::Secp256k1Error) -> ParseError {
+ ParseError::MalformedSignature(a, )
+}
+#[no_mangle]
+/// Utility method to constructs a new BadPrefix-variant ParseError
+pub extern "C" fn ParseError_bad_prefix() -> ParseError {
+ ParseError::BadPrefix}
+#[no_mangle]
+/// Utility method to constructs a new UnknownCurrency-variant ParseError
+pub extern "C" fn ParseError_unknown_currency() -> ParseError {
+ ParseError::UnknownCurrency}
+#[no_mangle]
+/// Utility method to constructs a new UnknownSiPrefix-variant ParseError
+pub extern "C" fn ParseError_unknown_si_prefix() -> ParseError {
+ ParseError::UnknownSiPrefix}
+#[no_mangle]
+/// Utility method to constructs a new MalformedHRP-variant ParseError
+pub extern "C" fn ParseError_malformed_hrp() -> ParseError {
+ ParseError::MalformedHRP}
+#[no_mangle]
+/// Utility method to constructs a new TooShortDataPart-variant ParseError
+pub extern "C" fn ParseError_too_short_data_part() -> ParseError {
+ ParseError::TooShortDataPart}
+#[no_mangle]
+/// Utility method to constructs a new UnexpectedEndOfTaggedFields-variant ParseError
+pub extern "C" fn ParseError_unexpected_end_of_tagged_fields() -> ParseError {
+ ParseError::UnexpectedEndOfTaggedFields}
+#[no_mangle]
+/// Utility method to constructs a new DescriptionDecodeError-variant ParseError
+pub extern "C" fn ParseError_description_decode_error(a: crate::c_types::Error) -> ParseError {
+ ParseError::DescriptionDecodeError(a, )