Skip to content

Commit 5cc662b

Browse files
committed
Add helper for getting claimable balance
It is annoying to have to match across all the enums of `Balance` to just pull out the `claimable_amount_satoshis` value. This helper makes it easier if you just want to amount.
1 parent fb140b5 commit 5cc662b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lightning/src/chain/channelmonitor.rs

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

654+
impl Balance {
655+
pub fn claimable_amount_satoshis(&self) -> u64 {
656+
match self {
657+
Balance::ClaimableOnChannelClose {
658+
claimable_amount_satoshis,
659+
} => *claimable_amount_satoshis,
660+
Balance::ClaimableAwaitingConfirmations {
661+
claimable_amount_satoshis,
662+
..
663+
} => *claimable_amount_satoshis,
664+
Balance::ContentiousClaimable {
665+
claimable_amount_satoshis,
666+
..
667+
} => *claimable_amount_satoshis,
668+
Balance::MaybeTimeoutClaimableHTLC {
669+
claimable_amount_satoshis,
670+
..
671+
} => *claimable_amount_satoshis,
672+
Balance::MaybePreimageClaimableHTLC {
673+
claimable_amount_satoshis,
674+
..
675+
} => *claimable_amount_satoshis,
676+
Balance::CounterpartyRevokedOutputClaimable {
677+
claimable_amount_satoshis,
678+
..
679+
} => *claimable_amount_satoshis,
680+
}
681+
}
682+
}
683+
654684
/// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
655685
#[derive(PartialEq, Eq)]
656686
struct IrrevocablyResolvedHTLC {

0 commit comments

Comments
 (0)