@@ -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 ;
26+ use bitcoin:: { Address , OutPoint , Txid } ;
2627
2728use std:: convert:: TryInto ;
2829use std:: default:: Default ;
@@ -339,3 +340,165 @@ impl UniffiCustomTypeConverter for Network {
339340 obj. 0 . to_string ( )
340341 }
341342}
343+
344+ /// Details of a channel as returned by [`Node::list_channels`].
345+ ///
346+ /// [`Node::list_channels`]: [`crate::Node::list_channels`]
347+ pub struct ChannelDetails {
348+ /// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
349+ /// thereafter this is the transaction ID of the funding transaction XOR the funding transaction
350+ /// output).
351+ ///
352+ /// Note that this means this value is *not* persistent - it can change once during the
353+ /// lifetime of the channel.
354+ pub channel_id : ChannelId ,
355+ /// The `node_id` of our channel's counterparty.
356+ pub counterparty_node_id : PublicKey ,
357+ /// The channel's funding transaction output, if we've negotiated the funding transaction with
358+ /// our counterparty already.
359+ pub funding_txo : Option < OutPoint > ,
360+ /// Position of the funding transaction on-chain. `None` unless the funding transaction has been
361+ /// confirmed and the channel is fully opened.
362+ ///
363+ /// Note that if [`inbound_scid_alias`] is set, it must be used for invoices and inbound
364+ /// payments instead of this.
365+ ///
366+ /// For channels with [`confirmations_required`] set to `Some(0)`, [`outbound_scid_alias`] may
367+ /// be used in place of this in outbound routes.
368+ ///
369+ /// [`inbound_scid_alias`]: Self::inbound_scid_alias
370+ /// [`outbound_scid_alias`]: Self::outbound_scid_alias
371+ /// [`confirmations_required`]: Self::confirmations_required
372+ pub short_channel_id : Option < u64 > ,
373+ /// An optional [`short_channel_id`] alias for this channel, randomly generated by us and
374+ /// usable in place of [`short_channel_id`] to reference the channel in outbound routes when
375+ /// the channel has not yet been confirmed (as long as [`confirmations_required`] is
376+ /// `Some(0)`).
377+ ///
378+ /// This will be `None` as long as the channel is not available for routing outbound payments.
379+ ///
380+ /// [`short_channel_id`]: Self::short_channel_id
381+ /// [`confirmations_required`]: Self::confirmations_required
382+ pub outbound_scid_alias : Option < u64 > ,
383+ /// An optional [`short_channel_id`] alias for this channel, randomly generated by our
384+ /// counterparty and usable in place of [`short_channel_id`] in invoice route hints. Our
385+ /// counterparty will recognize the alias provided here in place of the [`short_channel_id`]
386+ /// when they see a payment to be routed to us.
387+ ///
388+ /// Our counterparty may choose to rotate this value at any time, though will always recognize
389+ /// previous values for inbound payment forwarding.
390+ ///
391+ /// [`short_channel_id`]: Self::short_channel_id
392+ pub inbound_scid_alias : Option < u64 > ,
393+ /// The value, in satoshis, of this channel as appears in the funding output.
394+ pub channel_value_satoshis : u64 ,
395+ /// The value, in satoshis, that must always be held in the channel for us. This value ensures
396+ /// that if we broadcast a revoked state, our counterparty can punish us by claiming at least
397+ /// this value on chain.
398+ ///
399+ /// This value is not included in [`outbound_capacity_msat`] as it can never be spent.
400+ ///
401+ /// This value will be `None` for outbound channels until the counterparty accepts the channel.
402+ ///
403+ /// [`outbound_capacity_msat`]: Self::outbound_capacity_msat
404+ pub unspendable_punishment_reserve : Option < u64 > ,
405+ /// The local `user_channel_id` of this channel.
406+ pub user_channel_id : UserChannelId ,
407+ /// Total balance of the channel. This is the amount that will be returned to the user if the
408+ /// channel is closed.
409+ ///
410+ /// The value is not exact, due to potential in-flight and fee-rate changes. Therefore, exactly
411+ /// this amount is likely irrecoverable on close.
412+ pub balance_msat : u64 ,
413+ /// Available outbound capacity for sending HTLCs to the remote peer.
414+ ///
415+ /// The amount does not include any pending HTLCs which are not yet resolved (and, thus, whose
416+ /// balance is not available for inclusion in new outbound HTLCs). This further does not include
417+ /// any pending outgoing HTLCs which are awaiting some other resolution to be sent.
418+ pub outbound_capacity_msat : u64 ,
419+ /// Available outbound capacity for sending HTLCs to the remote peer.
420+ ///
421+ /// The amount does not include any pending HTLCs which are not yet resolved
422+ /// (and, thus, whose balance is not available for inclusion in new inbound HTLCs). This further
423+ /// does not include any pending outgoing HTLCs which are awaiting some other resolution to be
424+ /// sent.
425+ pub inbound_capacity_msat : u64 ,
426+ /// The number of required confirmations on the funding transactions before the funding is
427+ /// considered "locked". The amount is selected by the channel fundee.
428+ ///
429+ /// The value will be `None` for outbound channels until the counterparty accepts the channel.
430+ pub confirmations_required : Option < u32 > ,
431+ /// The current number of confirmations on the funding transaction.
432+ pub confirmations : Option < u32 > ,
433+ /// Returns `true` if the channel was initiated (and therefore funded) by us.
434+ pub is_outbound : bool ,
435+ /// Returns `true` if the channel is confirmed, both parties have exchanged `channel_ready`
436+ /// messages, and the channel is not currently being shut down. Both parties exchange
437+ /// `channel_ready` messages upon independently verifying that the required confirmations count
438+ /// provided by `confirmations_required` has been reached.
439+ pub is_channel_ready : bool ,
440+ /// Returns `true` if the channel is (a) confirmed and `channel_ready` has been exchanged,
441+ /// (b) the peer is connected, and (c) the channel is not currently negotiating shutdown.
442+ ///
443+ /// This is a strict superset of `is_channel_ready`.
444+ pub is_usable : bool ,
445+ /// Returns `true` if this channel is (or will be) publicly-announced
446+ pub is_public : bool ,
447+ /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
448+ /// the channel.
449+ pub cltv_expiry_delta : Option < u16 > ,
450+ }
451+
452+ impl From < LdkChannelDetails > for ChannelDetails {
453+ fn from ( value : LdkChannelDetails ) -> Self {
454+ ChannelDetails {
455+ channel_id : ChannelId ( value. channel_id ) ,
456+ counterparty_node_id : value. counterparty . node_id ,
457+ funding_txo : value. funding_txo . and_then ( |o| Some ( o. into_bitcoin_outpoint ( ) ) ) ,
458+ short_channel_id : value. short_channel_id ,
459+ outbound_scid_alias : value. outbound_scid_alias ,
460+ inbound_scid_alias : value. inbound_scid_alias ,
461+ channel_value_satoshis : value. channel_value_satoshis ,
462+ unspendable_punishment_reserve : value. unspendable_punishment_reserve ,
463+ user_channel_id : UserChannelId ( value. user_channel_id ) ,
464+ balance_msat : value. balance_msat ,
465+ outbound_capacity_msat : value. outbound_capacity_msat ,
466+ inbound_capacity_msat : value. inbound_capacity_msat ,
467+ confirmations_required : value. confirmations_required ,
468+ confirmations : value. confirmations ,
469+ is_outbound : value. is_outbound ,
470+ is_channel_ready : value. is_channel_ready ,
471+ is_usable : value. is_usable ,
472+ is_public : value. is_public ,
473+ cltv_expiry_delta : value. config . and_then ( |c| Some ( c. cltv_expiry_delta ) ) ,
474+ }
475+ }
476+ }
477+
478+ impl UniffiCustomTypeConverter for Txid {
479+ type Builtin = String ;
480+
481+ fn into_custom ( val : Self :: Builtin ) -> uniffi:: Result < Self > {
482+ if let Ok ( txid) = Txid :: from_str ( & val) {
483+ return Ok ( txid) ;
484+ }
485+
486+ Err ( Error :: InvalidTxid . into ( ) )
487+ }
488+
489+ fn from_custom ( obj : Self ) -> Self :: Builtin {
490+ obj. to_string ( )
491+ }
492+ }
493+
494+ /// Details of a known lightning peer as returned by [`Node::list_peers`].
495+ ///
496+ /// [`Node::list_peers`]: [`crate::Node::list_peers`]
497+ pub struct PeerDetails {
498+ /// Our peer's node ID.
499+ pub node_id : PublicKey ,
500+ /// The IP address and TCP port of the peer.
501+ pub address : SocketAddr ,
502+ /// Indicates whether or not the user is currently has an active connection with the peer.
503+ pub is_connected : bool ,
504+ }
0 commit comments