-pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKeys, offered: bool) -> Script {
- get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key, offered)
+pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKeys) -> Script {
+ get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key)
+}
+
+pub fn build_htlc_transaction(prev_hash: &Sha256dHash, feerate_per_kw: u64, to_self_delay: u16, htlc: &HTLCOutputInCommitment, a_delayed_payment_key: &PublicKey, revocation_key: &PublicKey) -> Transaction {
+ let mut txins: Vec<TxIn> = Vec::new();
+ txins.push(TxIn {
+ previous_output: OutPoint {
+ txid: prev_hash.clone(),
+ vout: htlc.transaction_output_index,
+ },
+ script_sig: Script::new(),
+ sequence: 0,
+ witness: Vec::new(),
+ });
+
+ let total_fee = if htlc.offered {
+ feerate_per_kw * HTLC_TIMEOUT_TX_WEIGHT / 1000
+ } else {
+ feerate_per_kw * HTLC_SUCCESS_TX_WEIGHT / 1000
+ };
+
+ let mut txouts: Vec<TxOut> = Vec::new();
+ txouts.push(TxOut {
+ script_pubkey: get_revokeable_redeemscript(revocation_key, to_self_delay, a_delayed_payment_key).to_v0_p2wsh(),
+ value: htlc.amount_msat / 1000 - total_fee //TODO: BOLT 3 does not specify if we should add amount_msat before dividing or if we should divide by 1000 before subtracting (as we do here)
+ });
+
+ Transaction {
+ version: 2,
+ lock_time: if htlc.offered { htlc.cltv_expiry } else { 0 },
+ input: txins,
+ output: txouts,
+ }