- if !htlc.offered {
- // TODO: If the HTLC has already expired, potentially merge it with the
- // rest of the claim transaction, as above.
- let input = TxIn {
- previous_output: BitcoinOutPoint {
- txid: commitment_txid,
- vout: transaction_output_index,
- },
- script_sig: Script::new(),
- sequence: 0xff_ff_ff_fd,
- witness: Vec::new(),
- };
- let mut timeout_tx = Transaction {
- version: 2,
- lock_time: htlc.cltv_expiry,
- input: vec![input],
- output: vec!(TxOut {
- script_pubkey: self.destination_script.clone(),
- value: htlc.amount_msat / 1000,
- }),
- };
- let predicted_weight = timeout_tx.get_weight() + Self::get_witnesses_weight(&[InputDescriptors::ReceivedHTLC]);
- let height_timer = Self::get_height_timer(height, htlc.cltv_expiry);
- let mut used_feerate;
- if subtract_high_prio_fee!(self, fee_estimator, timeout_tx.output[0].value, predicted_weight, used_feerate) {
- let sighash_parts = bip143::SighashComponents::new(&timeout_tx);
- let (redeemscript, htlc_key) = sign_input!(sighash_parts, timeout_tx.input[0], htlc.amount_msat / 1000, vec![0], idx);
- assert!(predicted_weight >= timeout_tx.get_weight());
- //TODO: track SpendableOutputDescriptor
- log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", timeout_tx.input[0].previous_output.txid, timeout_tx.input[0].previous_output.vout, height_timer);
- let mut per_input_material = HashMap::with_capacity(1);
- per_input_material.insert(timeout_tx.input[0].previous_output, InputMaterial::RemoteHTLC { script : redeemscript, key: htlc_key, preimage: None, amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry });
- match self.claimable_outpoints.entry(timeout_tx.input[0].previous_output) {
- hash_map::Entry::Occupied(_) => {},
- hash_map::Entry::Vacant(entry) => { entry.insert((timeout_tx.txid(), height)); }
- }
- match self.pending_claim_requests.entry(timeout_tx.txid()) {
- hash_map::Entry::Occupied(_) => {},
- hash_map::Entry::Vacant(entry) => { entry.insert(ClaimTxBumpMaterial { height_timer, feerate_previous: used_feerate, soonest_timelock: htlc.cltv_expiry, per_input_material }); }
- }
- }
- txn_to_broadcast.push(timeout_tx);
- }
- }
- }
-
- if inputs.is_empty() { return (txn_to_broadcast, (commitment_txid, watch_outputs), spendable_outputs); } // Nothing to be done...probably a false positive/local tx
-
- let outputs = vec!(TxOut {
- script_pubkey: self.destination_script.clone(),
- value: total_value
- });
- let mut spend_tx = Transaction {
- version: 2,
- lock_time: 0,
- input: inputs,
- output: outputs,
- };
-
- let predicted_weight = spend_tx.get_weight() + Self::get_witnesses_weight(&inputs_desc[..]);
-
- let mut used_feerate;
- if !subtract_high_prio_fee!(self, fee_estimator, spend_tx.output[0].value, predicted_weight, used_feerate) {
- return (txn_to_broadcast, (commitment_txid, watch_outputs), spendable_outputs);
- }
-
- let sighash_parts = bip143::SighashComponents::new(&spend_tx);
-
- let mut per_input_material = HashMap::with_capacity(spend_tx.input.len());
- let mut soonest_timelock = ::std::u32::MAX;
- for info in inputs_info.iter() {
- if info.2 <= soonest_timelock {
- soonest_timelock = info.2;
- }
- }
- let height_timer = Self::get_height_timer(height, soonest_timelock);
- let spend_txid = spend_tx.txid();
- for (input, info) in spend_tx.input.iter_mut().zip(inputs_info.iter()) {
- let (redeemscript, htlc_key) = sign_input!(sighash_parts, input, info.1, (info.0).0.to_vec(), info.3);
- log_trace!(self, "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}", input.previous_output.txid, input.previous_output.vout, height_timer);
- per_input_material.insert(input.previous_output, InputMaterial::RemoteHTLC { script: redeemscript, key: htlc_key, preimage: Some(*(info.0)), amount: info.1, locktime: 0});
- match self.claimable_outpoints.entry(input.previous_output) {
- hash_map::Entry::Occupied(_) => {},
- hash_map::Entry::Vacant(entry) => { entry.insert((spend_txid, height)); }