From 3a85afdd7cfe88f9244eebd7f2b9dff34548eef5 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Fri, 2 Jun 2023 14:39:16 -0500 Subject: [PATCH] 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. --- lightning/src/chain/channelmonitor.rs | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index a48f169a4d5..6a029f1a66f 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -651,6 +651,40 @@ pub enum Balance { }, } +impl Balance { + /// The amount claimable, in satoshis. This could be restricted by a timeout or potentially + /// claimed by our counterparty. See the variant documentation for more details. + /// + /// On-chain fees required to claim the balance are not included in this amount. + pub fn claimable_amount_satoshis(&self) -> u64 { + match self { + Balance::ClaimableOnChannelClose { + claimable_amount_satoshis, + } => *claimable_amount_satoshis, + Balance::ClaimableAwaitingConfirmations { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + Balance::ContentiousClaimable { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + Balance::MaybePreimageClaimableHTLC { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + Balance::CounterpartyRevokedOutputClaimable { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + } + } +} + /// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY. #[derive(PartialEq, Eq)] struct IrrevocablyResolvedHTLC {