- match self.claimable_outpoints.get(&commitment_txid) {
- None => {},
- Some(per_commitment_data) => {
- let mut htlc_idx = 0;
- for (idx, input) in spend_tx.input.iter_mut().enumerate() {
- if idx == 0 { continue; } // We already signed the first input
-
- let mut htlc;
- while {
- htlc = &per_commitment_data.htlcs[htlc_idx].0;
- htlc_idx += 1;
- htlc.cltv_expiry > height + CLTV_CLAIM_BUFFER
- } {}
-
- let sig = match self.revocation_base_key {
- RevocationStorage::PrivMode { ref revocation_base_key } => {
- let htlc_redeemscript = chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey, htlc.offered);
- let sighash = ignore_error!(Message::from_slice(&sighash_parts.sighash_all(&input, &htlc_redeemscript, values_drain.next().unwrap())[..]));
+ txn_to_broadcast.push(spend_tx);
+ } else if let Some(per_commitment_data) = per_commitment_option {
+ if let Some(revocation_points) = self.their_cur_revocation_points {
+ let revocation_point_option =
+ if revocation_points.0 == commitment_number { Some(&revocation_points.1) }
+ else if let Some(point) = revocation_points.2.as_ref() {
+ if revocation_points.0 == commitment_number + 1 { Some(point) } else { None }
+ } else { None };
+ if let Some(revocation_point) = revocation_point_option {
+ let (revocation_pubkey, b_htlc_key) = match self.key_storage {
+ KeyStorage::PrivMode { ref revocation_base_key, ref htlc_base_key } => {
+ (ignore_error!(chan_utils::derive_public_revocation_key(&self.secp_ctx, revocation_point, &ignore_error!(PublicKey::from_secret_key(&self.secp_ctx, &revocation_base_key)))),
+ ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, revocation_point, &ignore_error!(PublicKey::from_secret_key(&self.secp_ctx, &htlc_base_key)))))
+ },
+ KeyStorage::SigsMode { ref revocation_base_key, ref htlc_base_key, .. } => {
+ (ignore_error!(chan_utils::derive_public_revocation_key(&self.secp_ctx, revocation_point, &revocation_base_key)),
+ ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, revocation_point, &htlc_base_key)))
+ },
+ };
+ let a_htlc_key = match self.their_htlc_base_key {
+ None => return txn_to_broadcast,
+ Some(their_htlc_base_key) => ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, revocation_point, &their_htlc_base_key)),
+ };
+
+ let mut total_value = 0;
+ let mut values = Vec::new();
+ let mut inputs = Vec::new();
+
+ macro_rules! sign_input {
+ ($sighash_parts: expr, $input: expr, $amount: expr, $preimage: expr) => {
+ {
+ let (sig, redeemscript) = match self.key_storage {
+ KeyStorage::PrivMode { ref htlc_base_key, .. } => {
+ let htlc = &per_commitment_option.unwrap()[$input.sequence as usize];
+ let redeemscript = chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &a_htlc_key, &b_htlc_key, &revocation_pubkey);
+ let sighash = ignore_error!(Message::from_slice(&$sighash_parts.sighash_all(&$input, &redeemscript, $amount)[..]));
+ let htlc_key = ignore_error!(chan_utils::derive_private_key(&self.secp_ctx, revocation_point, &htlc_base_key));
+ (ignore_error!(self.secp_ctx.sign(&sighash, &htlc_key)), redeemscript)
+ },
+ KeyStorage::SigsMode { .. } => {
+ unimplemented!();
+ }
+ };
+ $input.witness.push(sig.serialize_der(&self.secp_ctx).to_vec());
+ $input.witness[0].push(SigHashType::All as u8);
+ $input.witness.push($preimage);
+ $input.witness.push(redeemscript.into_vec());
+ }
+ }
+ }