+
+ //TODO: getting lastest local transactions should be infaillible and result in us "force-closing the channel", but we may
+ // have empty local commitment transaction if a ChannelMonitor is asked to force-close just after Channel::get_outbound_funding_created,
+ // before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing
+ // to monitor before.
+ pub(super) fn get_fully_signed_local_tx(&mut self, channel_value_satoshis: u64) -> Option<Transaction> {
+ if let Some(ref mut local_commitment) = self.local_commitment {
+ self.key_storage.sign_local_commitment(local_commitment, &self.funding_redeemscript, channel_value_satoshis, &self.secp_ctx);
+ return Some(local_commitment.with_valid_witness().clone());
+ }
+ None
+ }
+
+ #[cfg(test)]
+ pub(super) fn get_fully_signed_copy_local_tx(&mut self, channel_value_satoshis: u64) -> Option<Transaction> {
+ if let Some(ref mut local_commitment) = self.local_commitment {
+ let mut local_commitment = local_commitment.clone();
+ self.key_storage.unsafe_sign_local_commitment(&mut local_commitment, &self.funding_redeemscript, channel_value_satoshis, &self.secp_ctx);
+ return Some(local_commitment.with_valid_witness().clone());
+ }
+ None
+ }
+
+ pub(super) fn get_fully_signed_htlc_tx(&mut self, txid: Sha256dHash, htlc_index: u32, preimage: Option<PaymentPreimage>) -> Option<Transaction> {
+ //TODO: store preimage in OnchainTxHandler
+ if let Some(ref mut local_commitment) = self.local_commitment {
+ if local_commitment.txid() == txid {
+ self.key_storage.sign_htlc_transaction(local_commitment, htlc_index, preimage, self.local_csv, &self.secp_ctx);
+ return local_commitment.htlc_with_valid_witness(htlc_index).clone();
+ }
+ }
+ None
+ }