+
+ // If the channel is force closed, try to claim the output from this preimage.
+ // First check if a counterparty commitment transaction has been broadcasted:
+ macro_rules! claim_htlcs {
+ ($commitment_number: expr, $txid: expr) => {
+ let htlc_claim_reqs = self.get_counterparty_htlc_output_claim_reqs($commitment_number, $txid, None);
+ self.onchain_tx_handler.update_claims_view(&Vec::new(), htlc_claim_reqs, None, broadcaster, fee_estimator, logger);
+ }
+ }
+ if let Some(txid) = self.current_counterparty_commitment_txid {
+ if let Some(commitment_number) = self.counterparty_commitment_txn_on_chain.get(&txid) {
+ claim_htlcs!(*commitment_number, txid);
+ return;
+ }
+ }
+ if let Some(txid) = self.prev_counterparty_commitment_txid {
+ if let Some(commitment_number) = self.counterparty_commitment_txn_on_chain.get(&txid) {
+ claim_htlcs!(*commitment_number, txid);
+ return;
+ }
+ }
+
+ // Then if a holder commitment transaction has been seen on-chain, broadcast transactions
+ // claiming the HTLC output from each of the holder commitment transactions.
+ // Note that we can't just use `self.holder_tx_signed`, because that only covers the case where
+ // *we* sign a holder commitment transaction, not when e.g. a watchtower broadcasts one of our
+ // holder commitment transactions.
+ if self.broadcasted_holder_revokable_script.is_some() {
+ let (claim_reqs, _) = self.get_broadcasted_holder_claims(&self.current_holder_commitment_tx);
+ self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, None, broadcaster, fee_estimator, logger);
+ if let Some(ref tx) = self.prev_holder_signed_commitment_tx {
+ let (claim_reqs, _) = self.get_broadcasted_holder_claims(&tx);
+ self.onchain_tx_handler.update_claims_view(&Vec::new(), claim_reqs, None, broadcaster, fee_estimator, logger);
+ }
+ }