X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchan_utils.rs;h=1c068025b8f0853340dfc54e89ba347411cdf20a;hb=0456b0e311a4996b00d715f9211adcabc06b37c7;hp=d1489e2716836f928d5bdc04450f3d8722d4fbc9;hpb=c86cacd29d72c0af62cfd29d78dcf17a6d8f8c71;p=rust-lightning diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index d1489e27..1c068025 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -1599,6 +1599,11 @@ impl CommitmentTransaction { self.commitment_number } + /// The per commitment point used by the broadcaster. + pub fn per_commitment_point(&self) -> PublicKey { + self.keys.per_commitment_point + } + /// The value to be sent to the broadcaster pub fn to_broadcaster_value_sat(&self) -> u64 { self.to_broadcaster_value_sat @@ -1720,26 +1725,40 @@ impl<'a> TrustedCommitmentTransaction<'a> { Ok(ret) } - /// Gets a signed HTLC transaction given a preimage (for !htlc.offered) and the holder HTLC transaction signature. - pub(crate) fn get_signed_htlc_tx(&self, channel_parameters: &DirectedChannelTransactionParameters, htlc_index: usize, counterparty_signature: &Signature, signature: &Signature, preimage: &Option) -> Transaction { - let inner = self.inner; - let keys = &inner.keys; - let txid = inner.built.txid; - let this_htlc = &inner.htlcs[htlc_index]; + /// Builds the second-level holder HTLC transaction for the HTLC with index `htlc_index`. + pub(crate) fn build_unsigned_htlc_tx( + &self, channel_parameters: &DirectedChannelTransactionParameters, htlc_index: usize, + preimage: &Option, + ) -> Transaction { + let keys = &self.inner.keys; + let this_htlc = &self.inner.htlcs[htlc_index]; assert!(this_htlc.transaction_output_index.is_some()); // if we don't have preimage for an HTLC-Success, we can't generate an HTLC transaction. if !this_htlc.offered && preimage.is_none() { unreachable!(); } // Further, we should never be provided the preimage for an HTLC-Timeout transaction. if this_htlc.offered && preimage.is_some() { unreachable!(); } - let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key); + build_htlc_transaction( + &self.inner.built.txid, self.inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, + &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key + ) + } - let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, &self.channel_type_features, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key); - htlc_tx.input[0].witness = chan_utils::build_htlc_input_witness( - signature, counterparty_signature, preimage, &htlc_redeemscript, &self.channel_type_features, + /// Builds the witness required to spend the input for the HTLC with index `htlc_index` in a + /// second-level holder HTLC transaction. + pub(crate) fn build_htlc_input_witness( + &self, htlc_index: usize, counterparty_signature: &Signature, signature: &Signature, + preimage: &Option + ) -> Witness { + let keys = &self.inner.keys; + let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys( + &self.inner.htlcs[htlc_index], &self.channel_type_features, &keys.broadcaster_htlc_key, + &keys.countersignatory_htlc_key, &keys.revocation_key ); - htlc_tx + chan_utils::build_htlc_input_witness( + signature, counterparty_signature, preimage, &htlc_redeemscript, &self.channel_type_features, + ) } /// Returns the index of the revokeable output, i.e. the `to_local` output sending funds to