| 238 | } |
| 239 | |
| 240 | static void add_htlcs(struct bitcoin_tx ***txs, |
| 241 | const struct htlc **htlcmap, |
| 242 | const struct channel *channel, |
| 243 | const struct keyset *keyset, |
| 244 | enum side side) |
| 245 | { |
| 246 | struct bitcoin_outpoint outpoint; |
| 247 | u32 feerate_per_kw = channel_feerate(channel, side); |
| 248 | bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); |
| 249 | |
| 250 | /* Get txid of commitment transaction */ |
| 251 | bitcoin_txid((*txs)[0], &outpoint.txid); |
| 252 | |
| 253 | for (outpoint.n = 0; outpoint.n < tal_count(htlcmap); outpoint.n++) { |
| 254 | const struct htlc *htlc = htlcmap[outpoint.n]; |
| 255 | struct bitcoin_tx *tx; |
| 256 | struct ripemd160 ripemd; |
| 257 | const u8 *wscript; |
| 258 | |
| 259 | if (!htlc) |
| 260 | continue; |
| 261 | |
| 262 | if (htlc_owner(htlc) == side) { |
| 263 | ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); |
| 264 | wscript = htlc_offered_wscript(tmpctx, &ripemd, keyset, |
| 265 | option_anchor_outputs); |
| 266 | tx = htlc_timeout_tx(*txs, chainparams, &outpoint, |
| 267 | wscript, |
| 268 | htlc->amount, |
| 269 | htlc->expiry.locktime, |
| 270 | channel->config[!side].to_self_delay, |
| 271 | feerate_per_kw, |
| 272 | keyset, |
| 273 | option_anchor_outputs); |
| 274 | } else { |
| 275 | ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); |
| 276 | wscript = htlc_received_wscript(tmpctx, &ripemd, |
| 277 | &htlc->expiry, keyset, |
| 278 | option_anchor_outputs); |
| 279 | tx = htlc_success_tx(*txs, chainparams, &outpoint, |
| 280 | wscript, |
| 281 | htlc->amount, |
| 282 | channel->config[!side].to_self_delay, |
| 283 | feerate_per_kw, |
| 284 | keyset, |
| 285 | option_anchor_outputs); |
| 286 | } |
| 287 | |
| 288 | /* Append to array. */ |
| 289 | tal_arr_expand(txs, tx); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /* FIXME: We could cache these. */ |
| 294 | struct bitcoin_tx **channel_txs(const tal_t *ctx, |
no test coverage detected