MCPcopy Create free account
hub / github.com/ElementsProject/lightning / add_htlcs

Function add_htlcs

channeld/full_channel.c:229–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227}
228
229static void add_htlcs(struct bitcoin_tx ***txs,
230 const struct htlc **htlcmap,
231 const struct channel *channel,
232 const struct keyset *keyset,
233 enum side side)
234{
235 struct bitcoin_outpoint outpoint;
236 u32 htlc_feerate_per_kw;
237 bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED);
238 bool option_anchors_zero_fee_htlc_tx = channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX);
239
240 if (channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX))
241 htlc_feerate_per_kw = 0;
242 else
243 htlc_feerate_per_kw = channel_feerate(channel, side);
244
245 /* Get txid of commitment transaction */
246 bitcoin_txid((*txs)[0], &outpoint.txid);
247
248 for (outpoint.n = 0; outpoint.n < tal_count(htlcmap); outpoint.n++) {
249 const struct htlc *htlc = htlcmap[outpoint.n];
250 struct bitcoin_tx *tx;
251 struct ripemd160 ripemd;
252 const u8 *wscript;
253
254 if (!htlc)
255 continue;
256
257 if (htlc_owner(htlc) == side) {
258 ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8));
259 wscript = htlc_offered_wscript(tmpctx, &ripemd, keyset,
260 option_anchor_outputs,
261 option_anchors_zero_fee_htlc_tx);
262 tx = htlc_timeout_tx(*txs, chainparams, &outpoint,
263 wscript,
264 htlc->amount,
265 htlc->expiry.locktime,
266 channel->config[!side].to_self_delay,
267 htlc_feerate_per_kw,
268 keyset,
269 option_anchor_outputs,
270 option_anchors_zero_fee_htlc_tx);
271 } else {
272 ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8));
273 wscript = htlc_received_wscript(tmpctx, &ripemd,
274 &htlc->expiry, keyset,
275 option_anchor_outputs,
276 option_anchors_zero_fee_htlc_tx);
277 tx = htlc_success_tx(*txs, chainparams, &outpoint,
278 wscript,
279 htlc->amount,
280 channel->config[!side].to_self_delay,
281 htlc_feerate_per_kw,
282 keyset,
283 option_anchor_outputs,
284 option_anchors_zero_fee_htlc_tx);
285 }
286

Callers 1

channel_txsFunction · 0.85

Calls 9

channel_feerateFunction · 0.85
htlc_ownerFunction · 0.85
bitcoin_txidClass · 0.70
ripemd160Class · 0.70
channel_hasFunction · 0.50
htlc_offered_wscriptFunction · 0.50
htlc_timeout_txFunction · 0.50
htlc_received_wscriptFunction · 0.50
htlc_success_txFunction · 0.50

Tested by

no test coverage detected