X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fchannelmonitor.rs;h=1a9afb7cca75d55f4dc2d37de30c43b5e59f4ff1;hb=ba342de241f0b5e968d6ad0106e5690e7c9c68bc;hp=a48f169a4d5e605b330f49896bc191779dd389d7;hpb=64c58a565b9a4165d795ae7db608e1dc149829ca;p=rust-lightning diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index a48f169a..1a9afb7c 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 excludes balances that we are unsure if we are able + /// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more + /// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and + /// [`Balance::MaybePreimageClaimableHTLC`]. + /// + /// 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 { + .. + } => 0, + Balance::MaybePreimageClaimableHTLC { + .. + } => 0, + 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 { @@ -2505,7 +2539,7 @@ impl ChannelMonitorImpl { let mut ret = Vec::new(); mem::swap(&mut ret, &mut self.pending_events); #[cfg(anchors)] - for claim_event in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) { + for (claim_id, claim_event) in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) { match claim_event { ClaimEvent::BumpCommitment { package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx, @@ -2516,6 +2550,7 @@ impl ChannelMonitorImpl { let commitment_tx_fee_satoshis = self.channel_value_satoshis - commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value); ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose { + claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx, commitment_tx_fee_satoshis, @@ -2547,6 +2582,7 @@ impl ChannelMonitorImpl { }); } ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { + claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,