@@ -7,6 +7,7 @@ use crate::UniffiCustomTypeConverter;
77
88use lightning:: chain:: chainmonitor;
99use lightning:: chain:: keysinterface:: InMemorySigner ;
10+ use lightning:: ln:: channelmanager:: ChannelDetails as LdkChannelDetails ;
1011use lightning:: ln:: peer_handler:: IgnoringMessageHandler ;
1112use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
1213use lightning:: routing:: gossip;
@@ -22,7 +23,7 @@ use lightning_transaction_sync::EsploraSyncClient;
2223use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
2324use bitcoin:: hashes:: Hash ;
2425use bitcoin:: secp256k1:: PublicKey ;
25- use bitcoin:: { Address , Network , Txid } ;
26+ use bitcoin:: { Address , Network , OutPoint , Txid } ;
2627
2728use std:: convert:: TryInto ;
2829use std:: net:: SocketAddr ;
@@ -290,3 +291,113 @@ impl UniffiCustomTypeConverter for Txid {
290291 obj. to_string ( )
291292 }
292293}
294+
295+ /// Details of a channel as returned by [`Node::list_channels`].
296+ ///
297+ /// [`Node::list_channels`]: [`crate::Node::list_channels`]
298+ pub struct ChannelDetails {
299+ /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
300+ /// thereafter this is the transaction ID of the funding transaction XOR the funding transaction
301+ /// output).
302+ ///
303+ /// Note that this means this value is *not* persistent - it can change once during the
304+ /// lifetime of the channel.
305+ pub channel_id : ChannelId ,
306+ /// The `node_id` of our channel's counterparty.
307+ pub counterparty_node_id : PublicKey ,
308+ /// The channel's funding transaction output, if we've negotiated the funding transaction with
309+ /// our counterparty already.
310+ pub funding_txo : Option < OutPoint > ,
311+ /// The value, in satoshis, of this channel as appears in the funding output.
312+ pub channel_value_satoshis : u64 ,
313+ /// The value, in satoshis, that must always be held in the channel for us. This value ensures
314+ /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
315+ /// this value on chain.
316+ ///
317+ /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
318+ ///
319+ /// This value will be `None` for outbound channels until the counterparty accepts the channel.
320+ ///
321+ /// [`outbound_capacity_msat`]: Self::outbound_capacity_msat
322+ pub unspendable_punishment_reserve : Option < u64 > ,
323+ /// The local `user_channel_id` of this channel.
324+ pub user_channel_id : UserChannelId ,
325+ /// Total balance of the channel. This is the amount that will be returned to the user if the
326+ /// channel is closed.
327+ ///
328+ /// The value is not exact, due to potential in-flight and fee-rate changes. Therefore, exactly
329+ /// this amount is likely irrecoverable on close.
330+ pub balance_msat : u64 ,
331+ /// Available outbound capacity for sending HTLCs to the remote peer.
332+ ///
333+ /// The amount does not include any pending HTLCs which are not yet resolved (and, thus, whose
334+ /// balance is not available for inclusion in new outbound HTLCs). This further does not include
335+ /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
336+ pub outbound_capacity_msat : u64 ,
337+ /// Available outbound capacity for sending HTLCs to the remote peer.
338+ ///
339+ /// The amount does not include any pending HTLCs which are not yet resolved
340+ /// (and, thus, whose balance is not available for inclusion in new inbound HTLCs). This further
341+ /// does not include any pending outgoing HTLCs which are awaiting some other resolution to be
342+ /// sent.
343+ pub inbound_capacity_msat : u64 ,
344+ /// The number of required confirmations on the funding transactions before the funding is
345+ /// considered "locked". The amount is selected by the channel fundee.
346+ ///
347+ /// The value will be `None` for outbound channels until the counterparty accepts the channel.
348+ pub confirmations_required : Option < u32 > ,
349+ /// The current number of confirmations on the funding transaction.
350+ pub confirmations : Option < u32 > ,
351+ /// Returns `true` if the channel was initiated (and therefore funded) by us.
352+ pub is_outbound : bool ,
353+ /// Returns `true` if the channel is confirmed, both parties have exchanged `channel_ready`
354+ /// messages, and the channel is not currently being shut down. Both parties exchange
355+ /// `channel_ready` messages upon independently verifying that the required confirmations count
356+ /// provided by `confirmations_required` has been reached.
357+ pub is_channel_ready : bool ,
358+ /// Returns `true` if the channel is (a) confirmed and `channel_ready` has been exchanged,
359+ /// (b) the peer is connected, and (c) the channel is not currently negotiating shutdown.
360+ ///
361+ /// This is a strict superset of `is_channel_ready`.
362+ pub is_usable : bool ,
363+ /// Returns `true` if this channel is (or will be) publicly-announced
364+ pub is_public : bool ,
365+ /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
366+ /// the channel.
367+ pub cltv_expiry_delta : Option < u16 > ,
368+ }
369+
370+ impl From < LdkChannelDetails > for ChannelDetails {
371+ fn from ( value : LdkChannelDetails ) -> Self {
372+ ChannelDetails {
373+ channel_id : ChannelId ( value. channel_id ) ,
374+ counterparty_node_id : value. counterparty . node_id ,
375+ funding_txo : value. funding_txo . and_then ( |o| Some ( o. into_bitcoin_outpoint ( ) ) ) ,
376+ channel_value_satoshis : value. channel_value_satoshis ,
377+ unspendable_punishment_reserve : value. unspendable_punishment_reserve ,
378+ user_channel_id : UserChannelId ( value. user_channel_id ) ,
379+ balance_msat : value. balance_msat ,
380+ outbound_capacity_msat : value. outbound_capacity_msat ,
381+ inbound_capacity_msat : value. inbound_capacity_msat ,
382+ confirmations_required : value. confirmations_required ,
383+ confirmations : value. confirmations ,
384+ is_outbound : value. is_outbound ,
385+ is_channel_ready : value. is_channel_ready ,
386+ is_usable : value. is_usable ,
387+ is_public : value. is_public ,
388+ cltv_expiry_delta : value. config . and_then ( |c| Some ( c. cltv_expiry_delta ) ) ,
389+ }
390+ }
391+ }
392+
393+ /// Details of a known Lightning peer as returned by [`Node::list_peers`].
394+ ///
395+ /// [`Node::list_peers`]: [`crate::Node::list_peers`]
396+ pub struct PeerDetails {
397+ /// Our peer's node ID.
398+ pub node_id : PublicKey ,
399+ /// The IP address and TCP port of the peer.
400+ pub address : SocketAddr ,
401+ /// Indicates whether or not the user is currently has an active connection with the peer.
402+ pub is_connected : bool ,
403+ }
0 commit comments