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

Function new_htlc_out

lightningd/htlc_end.c:269–336  ·  view source on GitHub ↗

You need to set the ID, then connect_htlc_out this! */

Source from the content-addressed store, hash-verified

267
268/* You need to set the ID, then connect_htlc_out this! */
269struct htlc_out *new_htlc_out(const tal_t *ctx,
270 struct channel *channel,
271 struct amount_msat msat,
272 u32 cltv_expiry,
273 const struct sha256 *payment_hash,
274 const u8 *onion_routing_packet,
275 const struct pubkey *blinding,
276 bool am_origin,
277 struct amount_msat final_msat,
278 u64 partid,
279 u64 groupid,
280 struct htlc_in *in)
281{
282 struct htlc_out *hout = tal(ctx, struct htlc_out);
283
284 /* Mark this as an as of now unsaved HTLC */
285 hout->dbid = 0;
286
287 hout->key.channel = channel;
288 hout->key.id = HTLC_INVALID_ID;
289 hout->msat = msat;
290 hout->cltv_expiry = cltv_expiry;
291 hout->payment_hash = *payment_hash;
292 memcpy(hout->onion_routing_packet, onion_routing_packet,
293 sizeof(hout->onion_routing_packet));
294
295 hout->hstate = SENT_ADD_HTLC;
296 hout->failmsg = NULL;
297 hout->failonion = NULL;
298 hout->preimage = NULL;
299 hout->timeout = NULL;
300
301 hout->blinding = tal_dup_or_null(hout, struct pubkey, blinding);
302 hout->am_origin = am_origin;
303 if (am_origin) {
304 hout->partid = partid;
305 hout->groupid = groupid;
306
307 /* Stash the fees (for accounting) */
308 if (!amount_msat_sub(&hout->fees, msat, final_msat))
309 return corrupt("new_htlc_out",
310 "overflow subtract %s-%s",
311 type_to_string(tmpctx,
312 struct amount_msat,
313 &msat),
314 type_to_string(tmpctx,
315 struct amount_msat,
316 &final_msat));
317
318 }
319 hout->in = NULL;
320 if (in) {
321 htlc_out_connect_htlc_in(hout, in);
322
323 /* Stash the fees (for accounting) */
324 if (!amount_msat_sub(&hout->fees, in->msat, msat))
325 return corrupt("new_htlc_out",
326 "overflow subtract %s-%s",

Callers 1

send_htlc_outFunction · 0.85

Calls 5

amount_msat_subFunction · 0.85
htlc_out_connect_htlc_inFunction · 0.85
htlc_out_checkFunction · 0.85
corruptFunction · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected