Skip to content

Commit

Permalink
Introduce channel_type field to ChannelDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Jan 17, 2024
1 parent 8ff8e55 commit 0387783
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
38 changes: 38 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<OutPoint>,
/// The channel type as negotiated during channel opening.
///
/// Will be `None` until the channel negotiation has been completed.
pub channel_type: Option<ChannelType>,
/// 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
Expand Down Expand Up @@ -349,10 +370,27 @@ pub struct ChannelDetails {

impl From<LdkChannelDetails> 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),
Expand Down

0 comments on commit 0387783

Please sign in to comment.