|
| 1 | +use crate::ChannelId; |
| 2 | +use bitcoin::secp256k1::PublicKey; |
| 3 | +use lightning::chain::transaction::OutPoint as LdkOutpoint; |
| 4 | +use lightning::ln::channelmanager::ChannelDetails as LdkChannelDetails; |
| 5 | + |
| 6 | +/// Data structure that references and transaction output. |
| 7 | +pub struct OutPoint { |
| 8 | + /// The referenced transaction's txid. |
| 9 | + pub txid: String, |
| 10 | + /// The index of the referenced output in its transaction's vout. |
| 11 | + pub index: u16, |
| 12 | +} |
| 13 | + |
| 14 | +impl From<LdkOutpoint> for OutPoint { |
| 15 | + fn from(value: LdkOutpoint) -> Self { |
| 16 | + OutPoint { txid: value.txid.to_string(), index: value.index } |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +/// Details about the user's channel as returned by [`Node::list_channels`]. |
| 21 | +/// |
| 22 | +/// [`Node::list_channels`]: [`crate::Node::list_channels`] |
| 23 | +pub struct ChannelDetails { |
| 24 | + /// The channel's ID. |
| 25 | + pub channel_id: ChannelId, |
| 26 | + /// The `node_id` of our channel's counterparty. |
| 27 | + pub counterparty: PublicKey, |
| 28 | + /// Information about the channel's funding transaction output. `None `unless a funding |
| 29 | + /// transaction has been successfully negotiated with the channel's counterparty. |
| 30 | + pub funding_txo: Option<OutPoint>, |
| 31 | + /// Position of the funding transaction on-chain. `None` unless the funding transaction has been |
| 32 | + /// confirmed and fully opened. |
| 33 | + pub short_channel_id: Option<u64>, |
| 34 | + /// The value, in satoshis, of this channel as appears in the funding output. |
| 35 | + pub channel_value_satoshis: u64, |
| 36 | + /// Total balance of the channel. It is the amount that will be returned to the user if the |
| 37 | + /// channel is closed. The value is not exact, due to potential in-flight and fee-rate changes. |
| 38 | + /// Therefore, exactly this amount is likely irrecoverable on close. |
| 39 | + pub balance_msat: u64, |
| 40 | + /// Available outbound capacity for sending HTLCs to the remote peer. The amount does not |
| 41 | + /// include any pending HTLCs which are not yet resolved (and, thus, whose balance is not |
| 42 | + /// available for inclusion in new outbound HTLCs). This further does not include any |
| 43 | + /// pending outgoing HTLCs which are awaiting some other resolution to be sent. |
| 44 | + pub outbound_capacity_msat: u64, |
| 45 | + /// Available outbound capacity for sending HTLCs to the remote peer. The amount does not |
| 46 | + /// include any pending HTLCs which are not yet resolved (and, thus, whose balance is not |
| 47 | + /// available for inclusion in new inbound HTLCs). This further does not include any |
| 48 | + /// pending outgoing HTLCs which are awaiting some other resolution to be sent. |
| 49 | + pub inbound_capacity_msat: u64, |
| 50 | + /// The number of required confirmations on the funding transactions before the funding is |
| 51 | + /// considered "locked". The amount is selected by the channel fundee. |
| 52 | + /// |
| 53 | + /// The value will be `None` for outbound channels until the counterparty accepts the channel. |
| 54 | + pub confirmations_required: Option<u32>, |
| 55 | + /// The current number of confirmations on the funding transaction. |
| 56 | + pub confirmations: Option<u32>, |
| 57 | + /// Returns `True` if the channel was initiated (and therefore funded) by us. |
| 58 | + pub is_outbound: bool, |
| 59 | + /// Returns `True` if the channel is confirmed, both parties have exchanged `channel_ready` |
| 60 | + /// messages, and the channel is not currently being shut down. Both parties exchange |
| 61 | + /// `channel_ready` messages upon independently verifying that the required confirmations count |
| 62 | + /// provided by `confirmations_required` has been reached. |
| 63 | + pub is_channel_ready: bool, |
| 64 | + /// Returns `True` if the channel is (a) confirmed and `channel_ready` has been exchanged, |
| 65 | + /// (b) the peer is connected, and (c) the channel is not currently negotiating shutdown. |
| 66 | + pub is_usable: bool, |
| 67 | + /// Returns `True` if this channel is (or will be) publicly-announced |
| 68 | + pub is_public: bool, |
| 69 | + /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over |
| 70 | + /// the channel. |
| 71 | + pub cltv_expiry_delta: Option<u16>, |
| 72 | +} |
| 73 | + |
| 74 | +impl From<LdkChannelDetails> for ChannelDetails { |
| 75 | + fn from(value: LdkChannelDetails) -> Self { |
| 76 | + ChannelDetails { |
| 77 | + channel_id: ChannelId(value.channel_id), |
| 78 | + counterparty: value.counterparty.node_id, |
| 79 | + funding_txo: value.funding_txo.and_then(|o| Some(o.into())), |
| 80 | + short_channel_id: value.short_channel_id, |
| 81 | + channel_value_satoshis: value.channel_value_satoshis, |
| 82 | + balance_msat: value.balance_msat, |
| 83 | + outbound_capacity_msat: value.outbound_capacity_msat, |
| 84 | + inbound_capacity_msat: value.inbound_capacity_msat, |
| 85 | + confirmations_required: value.confirmations_required, |
| 86 | + confirmations: value.confirmations, |
| 87 | + is_outbound: value.is_outbound, |
| 88 | + is_channel_ready: value.is_channel_ready, |
| 89 | + is_usable: value.is_usable, |
| 90 | + is_public: value.is_public, |
| 91 | + cltv_expiry_delta: value.config.and_then(|c| Some(c.cltv_expiry_delta)), |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments