Skip to content

Commit 0387783

Browse files
committed
Introduce channel_type field to ChannelDetails
1 parent 8ff8e55 commit 0387783

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
@@ -186,10 +186,18 @@ dictionary OutPoint {
186186
u32 vout;
187187
};
188188

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

src/lib.rs

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

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

src/types.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ impl Readable for UserChannelId {
219219
}
220220
}
221221

222+
/// The type of a channel, as negotiated during channel opening.
223+
///
224+
/// See [`BOLT 2`] for more information.
225+
///
226+
/// [`BOLT 2`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#defined-channel-types
227+
#[derive(Debug, Clone)]
228+
pub enum ChannelType {
229+
/// A channel of type `option_static_remotekey`.
230+
StaticRemoteKey,
231+
/// A channel of type `option_static_remotekey` that requires 0conf support.
232+
StaticRemoteKey0conf,
233+
/// A channel of type `option_anchors_zero_fee_htlc_tx`.
234+
Anchors,
235+
/// A channel of type `option_anchors_zero_fee_htlc_tx` that requires 0conf support.
236+
Anchors0conf,
237+
}
238+
222239
/// Details of a channel as returned by [`Node::list_channels`].
223240
///
224241
/// [`Node::list_channels`]: crate::Node::list_channels
@@ -236,6 +253,10 @@ pub struct ChannelDetails {
236253
/// The channel's funding transaction output, if we've negotiated the funding transaction with
237254
/// our counterparty already.
238255
pub funding_txo: Option<OutPoint>,
256+
/// The channel type as negotiated during channel opening.
257+
///
258+
/// Will be `None` until the channel negotiation has been completed.
259+
pub channel_type: Option<ChannelType>,
239260
/// The value, in satoshis, of this channel as it appears in the funding output.
240261
pub channel_value_sats: u64,
241262
/// 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 {
349370

350371
impl From<LdkChannelDetails> for ChannelDetails {
351372
fn from(value: LdkChannelDetails) -> Self {
373+
let channel_type = value.channel_type.map(|t| {
374+
if t.supports_anchors_zero_fee_htlc_tx() {
375+
if t.requires_zero_conf() {
376+
ChannelType::Anchors0conf
377+
} else {
378+
ChannelType::Anchors
379+
}
380+
} else {
381+
if t.requires_zero_conf() {
382+
ChannelType::StaticRemoteKey0conf
383+
} else {
384+
ChannelType::StaticRemoteKey
385+
}
386+
}
387+
});
388+
352389
ChannelDetails {
353390
channel_id: value.channel_id,
354391
counterparty_node_id: value.counterparty.node_id,
355392
funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())),
393+
channel_type,
356394
channel_value_sats: value.channel_value_satoshis,
357395
unspendable_punishment_reserve: value.unspendable_punishment_reserve,
358396
user_channel_id: UserChannelId(value.user_channel_id),

0 commit comments

Comments
 (0)