@@ -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,149 @@ 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+ /// Position of the funding transaction on-chain. `None` unless the funding transaction has been
312+ /// confirmed and the channel is fully opened.
313+ ///
314+ /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
315+ /// payments instead of this.
316+ ///
317+ /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
318+ /// be used in place of this in outbound routes.
319+ ///
320+ /// [`inbound_scid_alias`]: Self::inbound_scid_alias
321+ /// [`outbound_scid_alias`]: Self::outbound_scid_alias
322+ /// [`confirmations_required`]: Self::confirmations_required
323+ pub short_channel_id : Option < u64 > ,
324+ /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
325+ /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
326+ /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
327+ /// `Some(0)`).
328+ ///
329+ /// This will be `None` as long as the channel is not available for routing outbound payments.
330+ ///
331+ /// [`short_channel_id`]: Self::short_channel_id
332+ /// [`confirmations_required`]: Self::confirmations_required
333+ pub outbound_scid_alias : Option < u64 > ,
334+ /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
335+ /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
336+ /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
337+ /// when they see a payment to be routed to us.
338+ ///
339+ /// Our counterparty may choose to rotate this value at any time, though will always recognize
340+ /// previous values for inbound payment forwarding.
341+ ///
342+ /// [`short_channel_id`]: Self::short_channel_id
343+ pub inbound_scid_alias : Option < u64 > ,
344+ /// The value, in satoshis, of this channel as appears in the funding output.
345+ pub channel_value_satoshis : u64 ,
346+ /// The value, in satoshis, that must always be held in the channel for us. This value ensures
347+ /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
348+ /// this value on chain.
349+ ///
350+ /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
351+ ///
352+ /// This value will be `None` for outbound channels until the counterparty accepts the channel.
353+ ///
354+ /// [`outbound_capacity_msat`]: Self::outbound_capacity_msat
355+ pub unspendable_punishment_reserve : Option < u64 > ,
356+ /// The local `user_channel_id` of this channel.
357+ pub user_channel_id : UserChannelId ,
358+ /// Total balance of the channel. This is the amount that will be returned to the user if the
359+ /// channel is closed.
360+ ///
361+ /// The value is not exact, due to potential in-flight and fee-rate changes. Therefore, exactly
362+ /// this amount is likely irrecoverable on close.
363+ pub balance_msat : u64 ,
364+ /// Available outbound capacity for sending HTLCs to the remote peer.
365+ ///
366+ /// The amount does not include any pending HTLCs which are not yet resolved (and, thus, whose
367+ /// balance is not available for inclusion in new outbound HTLCs). This further does not include
368+ /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
369+ pub outbound_capacity_msat : u64 ,
370+ /// Available outbound capacity for sending HTLCs to the remote peer.
371+ ///
372+ /// The amount does not include any pending HTLCs which are not yet resolved
373+ /// (and, thus, whose balance is not available for inclusion in new inbound HTLCs). This further
374+ /// does not include any pending outgoing HTLCs which are awaiting some other resolution to be
375+ /// sent.
376+ pub inbound_capacity_msat : u64 ,
377+ /// The number of required confirmations on the funding transactions before the funding is
378+ /// considered "locked". The amount is selected by the channel fundee.
379+ ///
380+ /// The value will be `None` for outbound channels until the counterparty accepts the channel.
381+ pub confirmations_required : Option < u32 > ,
382+ /// The current number of confirmations on the funding transaction.
383+ pub confirmations : Option < u32 > ,
384+ /// Returns `true` if the channel was initiated (and therefore funded) by us.
385+ pub is_outbound : bool ,
386+ /// Returns `true` if the channel is confirmed, both parties have exchanged `channel_ready`
387+ /// messages, and the channel is not currently being shut down. Both parties exchange
388+ /// `channel_ready` messages upon independently verifying that the required confirmations count
389+ /// provided by `confirmations_required` has been reached.
390+ pub is_channel_ready : bool ,
391+ /// Returns `true` if the channel is (a) confirmed and `channel_ready` has been exchanged,
392+ /// (b) the peer is connected, and (c) the channel is not currently negotiating shutdown.
393+ ///
394+ /// This is a strict superset of `is_channel_ready`.
395+ pub is_usable : bool ,
396+ /// Returns `true` if this channel is (or will be) publicly-announced
397+ pub is_public : bool ,
398+ /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
399+ /// the channel.
400+ pub cltv_expiry_delta : Option < u16 > ,
401+ }
402+
403+ impl From < LdkChannelDetails > for ChannelDetails {
404+ fn from ( value : LdkChannelDetails ) -> Self {
405+ ChannelDetails {
406+ channel_id : ChannelId ( value. channel_id ) ,
407+ counterparty_node_id : value. counterparty . node_id ,
408+ funding_txo : value. funding_txo . and_then ( |o| Some ( o. into_bitcoin_outpoint ( ) ) ) ,
409+ short_channel_id : value. short_channel_id ,
410+ outbound_scid_alias : value. outbound_scid_alias ,
411+ inbound_scid_alias : value. inbound_scid_alias ,
412+ channel_value_satoshis : value. channel_value_satoshis ,
413+ unspendable_punishment_reserve : value. unspendable_punishment_reserve ,
414+ user_channel_id : UserChannelId ( value. user_channel_id ) ,
415+ balance_msat : value. balance_msat ,
416+ outbound_capacity_msat : value. outbound_capacity_msat ,
417+ inbound_capacity_msat : value. inbound_capacity_msat ,
418+ confirmations_required : value. confirmations_required ,
419+ confirmations : value. confirmations ,
420+ is_outbound : value. is_outbound ,
421+ is_channel_ready : value. is_channel_ready ,
422+ is_usable : value. is_usable ,
423+ is_public : value. is_public ,
424+ cltv_expiry_delta : value. config . and_then ( |c| Some ( c. cltv_expiry_delta ) ) ,
425+ }
426+ }
427+ }
428+
429+ /// Details of a known lightning peer as returned by [`Node::list_peers`].
430+ ///
431+ /// [`Node::list_peers`]: [`crate::Node::list_peers`]
432+ pub struct PeerDetails {
433+ /// Our peer's node ID.
434+ pub node_id : PublicKey ,
435+ /// The IP address and TCP port of the peer.
436+ pub address : SocketAddr ,
437+ /// Indicates whether or not the user is currently has an active connection with the peer.
438+ pub is_connected : bool ,
439+ }
0 commit comments