Skip to content

Commit 99985c6

Browse files
authored
Merge pull request #2333 from benthecarman/chan-mon-bal-helper
Add helper for getting claimable balance
2 parents f09c370 + 06c6750 commit 99985c6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,40 @@ pub enum Balance {
651651
},
652652
}
653653

654+
impl Balance {
655+
/// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able
656+
/// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more
657+
/// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and
658+
/// [`Balance::MaybePreimageClaimableHTLC`].
659+
///
660+
/// On-chain fees required to claim the balance are not included in this amount.
661+
pub fn claimable_amount_satoshis(&self) -> u64 {
662+
match self {
663+
Balance::ClaimableOnChannelClose {
664+
claimable_amount_satoshis,
665+
} => *claimable_amount_satoshis,
666+
Balance::ClaimableAwaitingConfirmations {
667+
claimable_amount_satoshis,
668+
..
669+
} => *claimable_amount_satoshis,
670+
Balance::ContentiousClaimable {
671+
claimable_amount_satoshis,
672+
..
673+
} => *claimable_amount_satoshis,
674+
Balance::MaybeTimeoutClaimableHTLC {
675+
..
676+
} => 0,
677+
Balance::MaybePreimageClaimableHTLC {
678+
..
679+
} => 0,
680+
Balance::CounterpartyRevokedOutputClaimable {
681+
claimable_amount_satoshis,
682+
..
683+
} => *claimable_amount_satoshis,
684+
}
685+
}
686+
}
687+
654688
/// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
655689
#[derive(PartialEq, Eq)]
656690
struct IrrevocablyResolvedHTLC {

0 commit comments

Comments
 (0)