-/// The information we received from a peer along the route of a payment we originated. This is
-/// returned by ChannelMessageHandler::handle_update_fail_htlc to be passed into
-/// RoutingMessageHandler::handle_htlc_fail_channel_update to update our network map.
-#[must_use]
-#[derive(Clone)]
-#[repr(C)]
-pub enum HTLCFailChannelUpdate {
- /// We received an error which included a full ChannelUpdate message.
- ChannelUpdateMessage {
- /// The unwrapped message we received
- msg: crate::lightning::ln::msgs::ChannelUpdate,
- },
- /// We received an error which indicated only that a channel has been closed
- ChannelClosed {
- /// The short_channel_id which has now closed.
- short_channel_id: u64,
- /// when this true, this channel should be permanently removed from the
- /// consideration. Otherwise, this channel can be restored as new channel_update is received
- is_permanent: bool,
- },
- /// We received an error which indicated only that a node has failed
- NodeFailure {
- /// The node_id that has failed.
- node_id: crate::c_types::PublicKey,
- /// when this true, node should be permanently removed from the
- /// consideration. Otherwise, the channels connected to this node can be
- /// restored as new channel_update is received
- is_permanent: bool,
- },
-}
-use lightning::ln::msgs::HTLCFailChannelUpdate as nativeHTLCFailChannelUpdate;
-impl HTLCFailChannelUpdate {
- #[allow(unused)]
- pub(crate) fn to_native(&self) -> nativeHTLCFailChannelUpdate {
- match self {
- HTLCFailChannelUpdate::ChannelUpdateMessage {ref msg, } => {
- let mut msg_nonref = (*msg).clone();
- nativeHTLCFailChannelUpdate::ChannelUpdateMessage {
- msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) },
- }
- },
- HTLCFailChannelUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
- let mut short_channel_id_nonref = (*short_channel_id).clone();
- let mut is_permanent_nonref = (*is_permanent).clone();
- nativeHTLCFailChannelUpdate::ChannelClosed {
- short_channel_id: short_channel_id_nonref,
- is_permanent: is_permanent_nonref,
- }
- },
- HTLCFailChannelUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
- let mut node_id_nonref = (*node_id).clone();
- let mut is_permanent_nonref = (*is_permanent).clone();
- nativeHTLCFailChannelUpdate::NodeFailure {
- node_id: node_id_nonref.into_rust(),
- is_permanent: is_permanent_nonref,
- }
- },
- }
- }
- #[allow(unused)]
- pub(crate) fn into_native(self) -> nativeHTLCFailChannelUpdate {
- match self {
- HTLCFailChannelUpdate::ChannelUpdateMessage {mut msg, } => {
- nativeHTLCFailChannelUpdate::ChannelUpdateMessage {
- msg: *unsafe { Box::from_raw(msg.take_inner()) },
- }
- },
- HTLCFailChannelUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
- nativeHTLCFailChannelUpdate::ChannelClosed {
- short_channel_id: short_channel_id,
- is_permanent: is_permanent,
- }
- },
- HTLCFailChannelUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
- nativeHTLCFailChannelUpdate::NodeFailure {
- node_id: node_id.into_rust(),
- is_permanent: is_permanent,
- }
- },
- }
- }
- #[allow(unused)]
- pub(crate) fn from_native(native: &nativeHTLCFailChannelUpdate) -> Self {
- match native {
- nativeHTLCFailChannelUpdate::ChannelUpdateMessage {ref msg, } => {
- let mut msg_nonref = (*msg).clone();
- HTLCFailChannelUpdate::ChannelUpdateMessage {
- msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg_nonref)), is_owned: true },
- }
- },
- nativeHTLCFailChannelUpdate::ChannelClosed {ref short_channel_id, ref is_permanent, } => {
- let mut short_channel_id_nonref = (*short_channel_id).clone();
- let mut is_permanent_nonref = (*is_permanent).clone();
- HTLCFailChannelUpdate::ChannelClosed {
- short_channel_id: short_channel_id_nonref,
- is_permanent: is_permanent_nonref,
- }
- },
- nativeHTLCFailChannelUpdate::NodeFailure {ref node_id, ref is_permanent, } => {
- let mut node_id_nonref = (*node_id).clone();
- let mut is_permanent_nonref = (*is_permanent).clone();
- HTLCFailChannelUpdate::NodeFailure {
- node_id: crate::c_types::PublicKey::from_rust(&node_id_nonref),
- is_permanent: is_permanent_nonref,
- }
- },
- }
- }
- #[allow(unused)]
- pub(crate) fn native_into(native: nativeHTLCFailChannelUpdate) -> Self {
- match native {
- nativeHTLCFailChannelUpdate::ChannelUpdateMessage {mut msg, } => {
- HTLCFailChannelUpdate::ChannelUpdateMessage {
- msg: crate::lightning::ln::msgs::ChannelUpdate { inner: Box::into_raw(Box::new(msg)), is_owned: true },
- }
- },
- nativeHTLCFailChannelUpdate::ChannelClosed {mut short_channel_id, mut is_permanent, } => {
- HTLCFailChannelUpdate::ChannelClosed {
- short_channel_id: short_channel_id,
- is_permanent: is_permanent,
- }
- },
- nativeHTLCFailChannelUpdate::NodeFailure {mut node_id, mut is_permanent, } => {
- HTLCFailChannelUpdate::NodeFailure {
- node_id: crate::c_types::PublicKey::from_rust(&node_id),
- is_permanent: is_permanent,
- }
- },
- }
- }
-}
-/// Frees any resources used by the HTLCFailChannelUpdate
-#[no_mangle]
-pub extern "C" fn HTLCFailChannelUpdate_free(this_ptr: HTLCFailChannelUpdate) { }
-/// Creates a copy of the HTLCFailChannelUpdate
-#[no_mangle]
-pub extern "C" fn HTLCFailChannelUpdate_clone(orig: &HTLCFailChannelUpdate) -> HTLCFailChannelUpdate {
- orig.clone()
-}
-#[no_mangle]
-/// Utility method to constructs a new ChannelUpdateMessage-variant HTLCFailChannelUpdate
-pub extern "C" fn HTLCFailChannelUpdate_channel_update_message(msg: crate::lightning::ln::msgs::ChannelUpdate) -> HTLCFailChannelUpdate {
- HTLCFailChannelUpdate::ChannelUpdateMessage {
- msg,
- }
-}
-#[no_mangle]
-/// Utility method to constructs a new ChannelClosed-variant HTLCFailChannelUpdate
-pub extern "C" fn HTLCFailChannelUpdate_channel_closed(short_channel_id: u64, is_permanent: bool) -> HTLCFailChannelUpdate {
- HTLCFailChannelUpdate::ChannelClosed {
- short_channel_id,
- is_permanent,
- }
-}
-#[no_mangle]
-/// Utility method to constructs a new NodeFailure-variant HTLCFailChannelUpdate
-pub extern "C" fn HTLCFailChannelUpdate_node_failure(node_id: crate::c_types::PublicKey, is_permanent: bool) -> HTLCFailChannelUpdate {
- HTLCFailChannelUpdate::NodeFailure {
- node_id,
- is_permanent,
- }
-}