Skip to content

Commit

Permalink
feat: return funding txid for pending close channels
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmitr committed Jan 3, 2025
1 parent 3152b8a commit fdb3cd8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
12 changes: 12 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ interface LightningBalance {
ClaimableOnChannelClose (
ChannelId channel_id,
PublicKey counterparty_node_id,
Txid funding_tx_id,
u16 funding_tx_index,
u64 amount_satoshis,
u64 transaction_fee_satoshis,
u64 outbound_payment_htlc_rounded_msat,
Expand All @@ -456,13 +458,17 @@ interface LightningBalance {
ClaimableAwaitingConfirmations (
ChannelId channel_id,
PublicKey counterparty_node_id,
Txid funding_tx_id,
u16 funding_tx_index,
u64 amount_satoshis,
u32 confirmation_height,
BalanceSource source
);
ContentiousClaimable (
ChannelId channel_id,
PublicKey counterparty_node_id,
Txid funding_tx_id,
u16 funding_tx_index,
u64 amount_satoshis,
u32 timeout_height,
PaymentHash payment_hash,
Expand All @@ -471,6 +477,8 @@ interface LightningBalance {
MaybeTimeoutClaimableHTLC (
ChannelId channel_id,
PublicKey counterparty_node_id,
Txid funding_tx_id,
u16 funding_tx_index,
u64 amount_satoshis,
u32 claimable_height,
PaymentHash payment_hash,
Expand All @@ -479,13 +487,17 @@ interface LightningBalance {
MaybePreimageClaimableHTLC (
ChannelId channel_id,
PublicKey counterparty_node_id,
Txid funding_tx_id,
u16 funding_tx_index,
u64 amount_satoshis,
u32 expiry_height,
PaymentHash payment_hash
);
CounterpartyRevokedOutputClaimable (
ChannelId channel_id,
PublicKey counterparty_node_id,
Txid funding_tx_id,
u16 funding_tx_index,
u64 amount_satoshis
);
};
Expand Down
41 changes: 40 additions & 1 deletion src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use lightning::util::sweep::{OutputSpendStatus, TrackedSpendableOutput};

use bitcoin::secp256k1::PublicKey;
use bitcoin::{BlockHash, Txid};
use lightning::chain::transaction::OutPoint;

/// Details of the known available balances returned by [`Node::list_balances`].
///
Expand Down Expand Up @@ -79,6 +80,10 @@ pub enum LightningBalance {
channel_id: ChannelId,
/// The identifier of our channel counterparty.
counterparty_node_id: PublicKey,
/// Alby: funding transaction ID.
funding_tx_id: Txid,
/// Alby: funding transaction output index.
funding_tx_index: u16,
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
/// required to do so.
amount_satoshis: u64,
Expand Down Expand Up @@ -133,6 +138,10 @@ pub enum LightningBalance {
channel_id: ChannelId,
/// The identifier of our channel counterparty.
counterparty_node_id: PublicKey,
/// Alby: funding transaction ID.
funding_tx_id: Txid,
/// Alby: funding transaction output index.
funding_tx_index: u16,
/// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
/// were spent in broadcasting the transaction.
amount_satoshis: u64,
Expand All @@ -156,6 +165,10 @@ pub enum LightningBalance {
channel_id: ChannelId,
/// The identifier of our channel counterparty.
counterparty_node_id: PublicKey,
/// Alby: funding transaction ID.
funding_tx_id: Txid,
/// Alby: funding transaction output index.
funding_tx_index: u16,
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
/// required to do so.
amount_satoshis: u64,
Expand All @@ -175,6 +188,10 @@ pub enum LightningBalance {
channel_id: ChannelId,
/// The identifier of our channel counterparty.
counterparty_node_id: PublicKey,
/// Alby: funding transaction ID.
funding_tx_id: Txid,
/// Alby: funding transaction output index.
funding_tx_index: u16,
/// The amount potentially available to claim, in satoshis, excluding the on-chain fees
/// which will be required to do so.
amount_satoshis: u64,
Expand All @@ -194,6 +211,10 @@ pub enum LightningBalance {
channel_id: ChannelId,
/// The identifier of our channel counterparty.
counterparty_node_id: PublicKey,
/// Alby: funding transaction ID.
funding_tx_id: Txid,
/// Alby: funding transaction output index.
funding_tx_index: u16,
/// The amount potentially available to claim, in satoshis, excluding the on-chain fees
/// which will be required to do so.
amount_satoshis: u64,
Expand All @@ -213,15 +234,21 @@ pub enum LightningBalance {
channel_id: ChannelId,
/// The identifier of our channel counterparty.
counterparty_node_id: PublicKey,
/// Alby: funding transaction ID.
funding_tx_id: Txid,
/// Alby: funding transaction output index.
funding_tx_index: u16,
/// The amount, in satoshis, of the output which we can claim.
amount_satoshis: u64,
},
}

impl LightningBalance {
pub(crate) fn from_ldk_balance(
channel_id: ChannelId, counterparty_node_id: PublicKey, balance: LdkBalance,
channel_id: ChannelId, counterparty_node_id: PublicKey, funding_txo: OutPoint,
balance: LdkBalance,
) -> Self {
let OutPoint { txid: funding_tx_id, index: funding_tx_index } = funding_txo;
match balance {
LdkBalance::ClaimableOnChannelClose {
amount_satoshis,
Expand All @@ -233,6 +260,8 @@ impl LightningBalance {
} => Self::ClaimableOnChannelClose {
channel_id,
counterparty_node_id,
funding_tx_id,
funding_tx_index,
amount_satoshis,
transaction_fee_satoshis,
outbound_payment_htlc_rounded_msat,
Expand All @@ -247,6 +276,8 @@ impl LightningBalance {
} => Self::ClaimableAwaitingConfirmations {
channel_id,
counterparty_node_id,
funding_tx_id,
funding_tx_index,
amount_satoshis,
confirmation_height,
source,
Expand All @@ -259,6 +290,8 @@ impl LightningBalance {
} => Self::ContentiousClaimable {
channel_id,
counterparty_node_id,
funding_tx_id,
funding_tx_index,
amount_satoshis,
timeout_height,
payment_hash,
Expand All @@ -272,6 +305,8 @@ impl LightningBalance {
} => Self::MaybeTimeoutClaimableHTLC {
channel_id,
counterparty_node_id,
funding_tx_id,
funding_tx_index,
amount_satoshis,
claimable_height,
payment_hash,
Expand All @@ -284,6 +319,8 @@ impl LightningBalance {
} => Self::MaybePreimageClaimableHTLC {
channel_id,
counterparty_node_id,
funding_tx_id,
funding_tx_index,
amount_satoshis,
expiry_height,
payment_hash,
Expand All @@ -292,6 +329,8 @@ impl LightningBalance {
Self::CounterpartyRevokedOutputClaimable {
channel_id,
counterparty_node_id,
funding_tx_id,
funding_tx_index,
amount_satoshis,
}
},
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ impl Node {
lightning_balances.push(LightningBalance::from_ldk_balance(
channel_id,
counterparty_node_id,
funding_txo,
ldk_balance,
));
}
Expand Down

0 comments on commit fdb3cd8

Please sign in to comment.