Skip to content

Commit df66eac

Browse files
committed
Introduce channel_type field to ChannelDetails
1 parent b386313 commit df66eac

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
@@ -188,10 +188,18 @@ dictionary OutPoint {
188188
u32 vout;
189189
};
190190

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

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ use types::{
123123
Broadcaster, ChainMonitor, ChannelManager, FeeEstimator, KeysManager, NetworkGraph,
124124
PeerManager, Router, Scorer, Sweeper, Wallet,
125125
};
126-
pub use types::{ChannelDetails, PeerDetails, UserChannelId};
126+
pub use types::{ChannelDetails, ChannelType, PeerDetails, UserChannelId};
127127

128128
use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};
129129

src/types.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ impl Readable for UserChannelId {
157157
}
158158
}
159159

160+
/// The type of a channel, as negotiated during channel opening.
161+
///
162+
/// See [`BOLT 2`] for more information.
163+
///
164+
/// [`BOLT 2`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#defined-channel-types
165+
#[derive(Debug, Clone)]
166+
pub enum ChannelType {
167+
/// A channel of type `option_static_remotekey`.
168+
StaticRemoteKey,
169+
/// A channel of type `option_static_remotekey` that requires 0conf support.
170+
StaticRemoteKey0conf,
171+
/// A channel of type `option_anchors_zero_fee_htlc_tx`.
172+
Anchors,
173+
/// A channel of type `option_anchors_zero_fee_htlc_tx` that requires 0conf support.
174+
Anchors0conf,
175+
}
176+
160177
/// Details of a channel as returned by [`Node::list_channels`].
161178
///
162179
/// [`Node::list_channels`]: crate::Node::list_channels
@@ -174,6 +191,10 @@ pub struct ChannelDetails {
174191
/// The channel's funding transaction output, if we've negotiated the funding transaction with
175192
/// our counterparty already.
176193
pub funding_txo: Option<OutPoint>,
194+
/// The channel type as negotiated during channel opening.
195+
///
196+
/// Will be `None` until the channel negotiation has been completed.
197+
pub channel_type: Option<ChannelType>,
177198
/// The value, in satoshis, of this channel as it appears in the funding output.
178199
pub channel_value_sats: u64,
179200
/// The value, in satoshis, that must always be held as a reserve in the channel for us. This
@@ -287,10 +308,27 @@ pub struct ChannelDetails {
287308

288309
impl From<LdkChannelDetails> for ChannelDetails {
289310
fn from(value: LdkChannelDetails) -> Self {
311+
let channel_type = value.channel_type.map(|t| {
312+
if t.supports_anchors_zero_fee_htlc_tx() {
313+
if t.requires_zero_conf() {
314+
ChannelType::Anchors0conf
315+
} else {
316+
ChannelType::Anchors
317+
}
318+
} else {
319+
if t.requires_zero_conf() {
320+
ChannelType::StaticRemoteKey0conf
321+
} else {
322+
ChannelType::StaticRemoteKey
323+
}
324+
}
325+
});
326+
290327
ChannelDetails {
291328
channel_id: value.channel_id,
292329
counterparty_node_id: value.counterparty.node_id,
293330
funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())),
331+
channel_type,
294332
channel_value_sats: value.channel_value_satoshis,
295333
unspendable_punishment_reserve: value.unspendable_punishment_reserve,
296334
user_channel_id: UserChannelId(value.user_channel_id),

0 commit comments

Comments
 (0)