+
+ /// Check if any transaction broadcasted is paying fund back to some address we can assume to own
+ fn is_paying_spendable_output(&mut self, tx: &Transaction, height: u32) {
+ let mut spendable_output = None;
+ for (i, outp) in tx.output.iter().enumerate() { // There is max one spendable output for any channel tx, including ones generated by us
+ if outp.script_pubkey == self.destination_script {
+ spendable_output = Some(SpendableOutputDescriptor::StaticOutput {
+ outpoint: BitcoinOutPoint { txid: tx.txid(), vout: i as u32 },
+ output: outp.clone(),
+ });
+ break;
+ } else if let Some(ref broadcasted_local_revokable_script) = self.broadcasted_local_revokable_script {
+ if broadcasted_local_revokable_script.0 == outp.script_pubkey {
+ spendable_output = Some(SpendableOutputDescriptor::DynamicOutputP2WSH {
+ outpoint: BitcoinOutPoint { txid: tx.txid(), vout: i as u32 },
+ key: broadcasted_local_revokable_script.1,
+ witness_script: broadcasted_local_revokable_script.2.clone(),
+ to_self_delay: self.their_to_self_delay.unwrap(),
+ output: outp.clone(),
+ });
+ break;
+ }
+ } else if let Some(ref broadcasted_remote_payment_script) = self.broadcasted_remote_payment_script {
+ if broadcasted_remote_payment_script.0 == outp.script_pubkey {
+ spendable_output = Some(SpendableOutputDescriptor::DynamicOutputP2WPKH {
+ outpoint: BitcoinOutPoint { txid: tx.txid(), vout: i as u32 },
+ key: broadcasted_remote_payment_script.1,
+ output: outp.clone(),
+ });
+ break;
+ }
+ } else if outp.script_pubkey == self.shutdown_script {
+ spendable_output = Some(SpendableOutputDescriptor::StaticOutput {
+ outpoint: BitcoinOutPoint { txid: tx.txid(), vout: i as u32 },
+ output: outp.clone(),
+ });
+ }
+ }
+ if let Some(spendable_output) = spendable_output {
+ log_trace!(self, "Maturing {} until {}", log_spendable!(spendable_output), height + ANTI_REORG_DELAY - 1);
+ match self.onchain_events_waiting_threshold_conf.entry(height + ANTI_REORG_DELAY - 1) {
+ hash_map::Entry::Occupied(mut entry) => {
+ let e = entry.get_mut();
+ e.push(OnchainEvent::MaturingOutput { descriptor: spendable_output });
+ }
+ hash_map::Entry::Vacant(entry) => {
+ entry.insert(vec![OnchainEvent::MaturingOutput { descriptor: spendable_output }]);
+ }
+ }
+ }
+ }