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