+/// When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
+/// contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
+///
+/// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
+/// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
+#[derive(Clone)]
+#[must_use]
+#[repr(C)]
+pub enum PathFailure {
+ /// We failed to initially send the payment and no HTLC was committed to. Contains the relevant
+ /// error.
+ InitialSend {
+ /// The error surfaced from initial send.
+ err: crate::lightning::util::errors::APIError,
+ },
+ /// A hop on the path failed to forward our payment.
+ OnPath {
+ /// If present, this [`NetworkUpdate`] should be applied to the [`NetworkGraph`] so that routing
+ /// decisions can take into account the update.
+ ///
+ /// [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
+ /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
+ network_update: crate::c_types::derived::COption_NetworkUpdateZ,
+ },
+}
+use lightning::util::events::PathFailure as PathFailureImport;
+pub(crate) type nativePathFailure = PathFailureImport;
+
+impl PathFailure {
+ #[allow(unused)]
+ pub(crate) fn to_native(&self) -> nativePathFailure {
+ match self {
+ PathFailure::InitialSend {ref err, } => {
+ let mut err_nonref = Clone::clone(err);
+ nativePathFailure::InitialSend {
+ err: err_nonref.into_native(),
+ }
+ },
+ PathFailure::OnPath {ref network_update, } => {
+ let mut network_update_nonref = Clone::clone(network_update);
+ let mut local_network_update_nonref = { /* network_update_nonref*/ let network_update_nonref_opt = network_update_nonref; { } if network_update_nonref_opt.is_none() { None } else { Some({ network_update_nonref_opt.take().into_native() }) } };
+ nativePathFailure::OnPath {
+ network_update: local_network_update_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn into_native(self) -> nativePathFailure {
+ match self {
+ PathFailure::InitialSend {mut err, } => {
+ nativePathFailure::InitialSend {
+ err: err.into_native(),
+ }
+ },
+ PathFailure::OnPath {mut network_update, } => {
+ let mut local_network_update = { /* network_update*/ let network_update_opt = network_update; { } if network_update_opt.is_none() { None } else { Some({ network_update_opt.take().into_native() }) } };
+ nativePathFailure::OnPath {
+ network_update: local_network_update,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn from_native(native: &nativePathFailure) -> Self {
+ match native {
+ nativePathFailure::InitialSend {ref err, } => {
+ let mut err_nonref = Clone::clone(err);
+ PathFailure::InitialSend {
+ err: crate::lightning::util::errors::APIError::native_into(err_nonref),
+ }
+ },
+ nativePathFailure::OnPath {ref network_update, } => {
+ let mut network_update_nonref = Clone::clone(network_update);
+ let mut local_network_update_nonref = if network_update_nonref.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(network_update_nonref.unwrap()) }) };
+ PathFailure::OnPath {
+ network_update: local_network_update_nonref,
+ }
+ },
+ }
+ }
+ #[allow(unused)]
+ pub(crate) fn native_into(native: nativePathFailure) -> Self {
+ match native {
+ nativePathFailure::InitialSend {mut err, } => {
+ PathFailure::InitialSend {
+ err: crate::lightning::util::errors::APIError::native_into(err),
+ }
+ },
+ nativePathFailure::OnPath {mut network_update, } => {
+ let mut local_network_update = if network_update.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::gossip::NetworkUpdate::native_into(network_update.unwrap()) }) };
+ PathFailure::OnPath {
+ network_update: local_network_update,
+ }
+ },
+ }
+ }
+}
+/// Frees any resources used by the PathFailure
+#[no_mangle]
+pub extern "C" fn PathFailure_free(this_ptr: PathFailure) { }
+/// Creates a copy of the PathFailure
+#[no_mangle]
+pub extern "C" fn PathFailure_clone(orig: &PathFailure) -> PathFailure {
+ orig.clone()
+}
+#[no_mangle]
+/// Utility method to constructs a new InitialSend-variant PathFailure
+pub extern "C" fn PathFailure_initial_send(err: crate::lightning::util::errors::APIError) -> PathFailure {
+ PathFailure::InitialSend {
+ err,
+ }
+}
+#[no_mangle]
+/// Utility method to constructs a new OnPath-variant PathFailure
+pub extern "C" fn PathFailure_on_path(network_update: crate::c_types::derived::COption_NetworkUpdateZ) -> PathFailure {
+ PathFailure::OnPath {
+ network_update,
+ }
+}
+/// Checks if two PathFailures contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn PathFailure_eq(a: &PathFailure, b: &PathFailure) -> bool {
+ if &a.to_native() == &b.to_native() { true } else { false }
+}
+#[no_mangle]
+/// Serialize the PathFailure object into a byte array which can be read by PathFailure_read
+pub extern "C" fn PathFailure_write(obj: &crate::lightning::util::events::PathFailure) -> crate::c_types::derived::CVec_u8Z {
+ crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
+}
+#[no_mangle]
+/// Read a PathFailure from a byte array, created by PathFailure_write
+pub extern "C" fn PathFailure_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_PathFailureZDecodeErrorZ {
+ let res: Result<Option<lightning::util::events::PathFailure>, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser);
+ let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_PathFailureZ::None } else { crate::c_types::derived::COption_PathFailureZ::Some( { crate::lightning::util::events::PathFailure::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
+ local_res
+}