diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 2a961b29a..ee79ff8cf 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -186,10 +186,18 @@ dictionary OutPoint { u32 vout; }; +enum ChannelType { + "StaticRemoteKey", + "StaticRemoteKey0conf", + "Anchors", + "Anchors0conf", +}; + dictionary ChannelDetails { ChannelId channel_id; PublicKey counterparty_node_id; OutPoint? funding_txo; + ChannelType? channel_type; u64 channel_value_sats; u64? unspendable_punishment_reserve; UserChannelId user_channel_id; diff --git a/src/lib.rs b/src/lib.rs index 7454296f9..6e353468f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,7 +122,7 @@ use types::{ Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, FeeEstimator, KeysManager, NetworkGraph, PeerManager, Router, Scorer, Sweeper, Wallet, }; -pub use types::{ChannelDetails, Network, PeerDetails, UserChannelId}; +pub use types::{ChannelDetails, ChannelType, Network, PeerDetails, UserChannelId}; use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger}; diff --git a/src/types.rs b/src/types.rs index 39165e698..b6a52ca83 100644 --- a/src/types.rs +++ b/src/types.rs @@ -219,6 +219,23 @@ impl Readable for UserChannelId { } } +/// The type of a channel, as negotiated during channel opening. +/// +/// See [`BOLT 2`] for more information. +/// +/// [`BOLT 2`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#defined-channel-types +#[derive(Debug, Clone)] +pub enum ChannelType { + /// A channel of type `option_static_remotekey`. + StaticRemoteKey, + /// A channel of type `option_static_remotekey` that requires 0conf support. + StaticRemoteKey0conf, + /// A channel of type `option_anchors_zero_fee_htlc_tx`. + Anchors, + /// A channel of type `option_anchors_zero_fee_htlc_tx` that requires 0conf support. + Anchors0conf, +} + /// Details of a channel as returned by [`Node::list_channels`]. /// /// [`Node::list_channels`]: crate::Node::list_channels @@ -236,6 +253,10 @@ pub struct ChannelDetails { /// The channel's funding transaction output, if we've negotiated the funding transaction with /// our counterparty already. pub funding_txo: Option, + /// The channel type as negotiated during channel opening. + /// + /// Will be `None` until the channel negotiation has been completed. + pub channel_type: Option, /// The value, in satoshis, of this channel as it appears in the funding output. pub channel_value_sats: u64, /// The value, in satoshis, that must always be held as a reserve in the channel for us. This @@ -349,10 +370,27 @@ pub struct ChannelDetails { impl From for ChannelDetails { fn from(value: LdkChannelDetails) -> Self { + let channel_type = value.channel_type.map(|t| { + if t.supports_anchors_zero_fee_htlc_tx() { + if t.requires_zero_conf() { + ChannelType::Anchors0conf + } else { + ChannelType::Anchors + } + } else { + if t.requires_zero_conf() { + ChannelType::StaticRemoteKey0conf + } else { + ChannelType::StaticRemoteKey + } + } + }); + ChannelDetails { channel_id: value.channel_id, counterparty_node_id: value.counterparty.node_id, funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())), + channel_type, channel_value_sats: value.channel_value_satoshis, unspendable_punishment_reserve: value.unspendable_punishment_reserve, user_channel_id: UserChannelId(value.user_channel_id),