+/// This enum is used to specify which error data to send to peers when failing back an HTLC
+/// using [`ChannelManager::fail_htlc_backwards_with_reason`].
+///
+/// For more info on failure codes, see <https://github.com/lightning/bolts/blob/master/04-onion-routing.md#failure-messages>.
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum FailureCode {
+ /// We had a temporary error processing the payment. Useful if no other error codes fit
+ /// and you want to indicate that the payer may want to retry.
+ TemporaryNodeFailure,
+ /// We have a required feature which was not in this onion. For example, you may require
+ /// some additional metadata that was not provided with this payment.
+ RequiredNodeFeatureMissing,
+ /// You may wish to use this when a `payment_preimage` is unknown, or the CLTV expiry of
+ /// the HTLC is too close to the current block height for safe handling.
+ /// Using this failure code in [`ChannelManager::fail_htlc_backwards_with_reason`] is
+ /// equivalent to calling [`ChannelManager::fail_htlc_backwards`].
+ IncorrectOrUnknownPaymentDetails,
+}
+use lightning::ln::channelmanager::FailureCode as FailureCodeImport;
+pub(crate) type nativeFailureCode = FailureCodeImport;
+
+impl FailureCode {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativeFailureCode {
+ match self {
+ FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
+ FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
+ FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativeFailureCode {
+ match self {
+ FailureCode::TemporaryNodeFailure => nativeFailureCode::TemporaryNodeFailure,
+ FailureCode::RequiredNodeFeatureMissing => nativeFailureCode::RequiredNodeFeatureMissing,
+ FailureCode::IncorrectOrUnknownPaymentDetails => nativeFailureCode::IncorrectOrUnknownPaymentDetails,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativeFailureCode) -> Self {
+ match native {
+ nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
+ nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
+ nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativeFailureCode) -> Self {
+ match native {
+ nativeFailureCode::TemporaryNodeFailure => FailureCode::TemporaryNodeFailure,
+ nativeFailureCode::RequiredNodeFeatureMissing => FailureCode::RequiredNodeFeatureMissing,
+ nativeFailureCode::IncorrectOrUnknownPaymentDetails => FailureCode::IncorrectOrUnknownPaymentDetails,
+ }
+ }
+}
+/// Creates a copy of the FailureCode
+#[no_mangle]
+pub extern "C" fn FailureCode_clone(orig: &FailureCode) -> FailureCode {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new TemporaryNodeFailure-variant FailureCode
+pub extern "C" fn FailureCode_temporary_node_failure() -> FailureCode {
+ FailureCode::TemporaryNodeFailure}
+#[no_mangle]
+/// Utility method to constructs a new RequiredNodeFeatureMissing-variant FailureCode
+pub extern "C" fn FailureCode_required_node_feature_missing() -> FailureCode {
+ FailureCode::RequiredNodeFeatureMissing}
+#[no_mangle]
+/// Utility method to constructs a new IncorrectOrUnknownPaymentDetails-variant FailureCode
+pub extern "C" fn FailureCode_incorrect_or_unknown_payment_details() -> FailureCode {
+ FailureCode::IncorrectOrUnknownPaymentDetails}