Skip to content

Commit e63b804

Browse files
committed
Introduce channel_type field to ChannelDetails
1 parent e0d4e35 commit e63b804

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

bindings/ldk_node.udl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,18 @@ dictionary OutPoint {
187187
u32 vout;
188188
};
189189

190+
enum ChannelType {
191+
"StaticRemoteKey",
192+
"StaticRemoteKey0conf",
193+
"Anchors",
194+
"Anchors0conf",
195+
};
196+
190197
dictionary ChannelDetails {
191198
ChannelId channel_id;
192199
PublicKey counterparty_node_id;
193200
OutPoint? funding_txo;
201+
ChannelType? channel_type;
194202
u64 channel_value_sats;
195203
u64? unspendable_punishment_reserve;
196204
UserChannelId user_channel_id;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ use types::{
128128
Broadcaster, ChainMonitor, ChannelManager, FeeEstimator, KeysManager, NetworkGraph,
129129
PeerManager, Router, Scorer, Sweeper, Wallet,
130130
};
131-
pub use types::{ChannelDetails, PeerDetails, UserChannelId};
131+
pub use types::{ChannelDetails, ChannelType, PeerDetails, UserChannelId};
132132

133133
use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};
134134

src/types.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ impl Readable for UserChannelId {
154154
}
155155
}
156156

157+
/// The type of a channel, as negotiated during channel opening.
158+
///
159+
/// See [`BOLT 2`] for more information.
160+
///
161+
/// [`BOLT 2`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#defined-channel-types
162+
#[derive(Debug, Clone, PartialEq, Eq)]
163+
pub enum ChannelType {
164+
/// A channel of type `option_static_remotekey`.
165+
StaticRemoteKey,
166+
/// A channel of type `option_static_remotekey` that requires 0conf support.
167+
StaticRemoteKey0conf,
168+
/// A channel of type `option_anchors_zero_fee_htlc_tx`.
169+
Anchors,
170+
/// A channel of type `option_anchors_zero_fee_htlc_tx` that requires 0conf support.
171+
Anchors0conf,
172+
}
173+
157174
/// Details of a channel as returned by [`Node::list_channels`].
158175
///
159176
/// [`Node::list_channels`]: crate::Node::list_channels
@@ -171,6 +188,10 @@ pub struct ChannelDetails {
171188
/// The channel's funding transaction output, if we've negotiated the funding transaction with
172189
/// our counterparty already.
173190
pub funding_txo: Option<OutPoint>,
191+
/// The channel type as negotiated during channel opening.
192+
///
193+
/// Will be `None` until the channel negotiation has been completed.
194+
pub channel_type: Option<ChannelType>,
174195
/// The value, in satoshis, of this channel as it appears in the funding output.
175196
pub channel_value_sats: u64,
176197
/// The value, in satoshis, that must always be held as a reserve in the channel for us. This
@@ -284,10 +305,27 @@ pub struct ChannelDetails {
284305

285306
impl From<LdkChannelDetails> for ChannelDetails {
286307
fn from(value: LdkChannelDetails) -> Self {
308+
let channel_type = value.channel_type.map(|t| {
309+
if t.supports_anchors_zero_fee_htlc_tx() {
310+
if t.requires_zero_conf() {
311+
ChannelType::Anchors0conf
312+
} else {
313+
ChannelType::Anchors
314+
}
315+
} else {
316+
if t.requires_zero_conf() {
317+
ChannelType::StaticRemoteKey0conf
318+
} else {
319+
ChannelType::StaticRemoteKey
320+
}
321+
}
322+
});
323+
287324
ChannelDetails {
288325
channel_id: value.channel_id,
289326
counterparty_node_id: value.counterparty.node_id,
290327
funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())),
328+
channel_type,
291329
channel_value_sats: value.channel_value_satoshis,
292330
unspendable_punishment_reserve: value.unspendable_punishment_reserve,
293331
user_channel_id: UserChannelId(value.user_channel_id),

0 commit comments

Comments
 (0)