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

Function htlc_accepted_invoice_created

plugins/keysend.c:264–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264static struct command_result *
265htlc_accepted_invoice_created(struct command *cmd, const char *buf,
266 const jsmntok_t *result,
267 struct keysend_in *ki)
268{
269 struct tlv_field field;
270
271 /* Remove all unknown fields: complain about unused even ones!
272 * (Keysend is not a design, it's a kludge by people who
273 * didn't read the spec, and Just Made Something Work). */
274 for (size_t i = 0; i < tal_count(ki->payload->fields); i++) {
275 /* Odd fields are fine, leave them. */
276 if (ki->payload->fields[i].numtype % 2)
277 continue;
278 /* Same with known fields */
279 if (ki->payload->fields[i].meta)
280 continue;
281 /* Complain about it, at least. */
282 if (ki->preimage_field != &ki->payload->fields[i]) {
283 plugin_log(cmd->plugin, LOG_INFORM,
284 "Keysend payment uses illegal even field %"
285 PRIu64 ": stripping",
286 ki->payload->fields[i].numtype);
287 }
288 tal_arr_remove(&ki->payload->fields, i);
289 i--;
290 }
291
292 /* Now we can fill in the payment secret, from invoice. */
293 ki->payload->payment_data = tal(ki->payload,
294 struct tlv_tlv_payload_payment_data);
295 json_to_secret(buf, json_get_member(buf, result, "payment_secret"),
296 &ki->payload->payment_data->payment_secret);
297
298 /* We checked that amt_to_forward was non-NULL before */
299 ki->payload->payment_data->total_msat = *ki->payload->amt_to_forward;
300
301 /* In order to put payment_data into ->fields, I'd normally re-serialize,
302 * but we can have completely unknown fields. So insert manually. */
303 /* BOLT #4:
304 * 1. type: 8 (`payment_data`)
305 * 2. data:
306 * * [`32*byte`:`payment_secret`]
307 * * [`tu64`:`total_msat`]
308 */
309 field.numtype = 8;
310 field.value = tal_arr(ki->payload, u8, 0);
311 towire_secret(&field.value, &ki->payload->payment_data->payment_secret);
312 towire_tu64(&field.value, ki->payload->payment_data->total_msat);
313 field.length = tal_bytelen(field.value);
314 tal_arr_expand(&ki->payload->fields, field);
315
316 asort(ki->payload->fields, tal_count(ki->payload->fields),
317 tlvfield_cmp, NULL);
318
319 /* Finally we can resolve the payment with the preimage. */
320 plugin_log(cmd->plugin, LOG_INFORM,
321 "Resolving incoming HTLC with preimage for payment_hash %s "

Callers

nothing calls this directly

Calls 8

towire_secretFunction · 0.85
tal_bytelenFunction · 0.85
tal_hexstrFunction · 0.85
htlc_accepted_continueFunction · 0.85
plugin_logFunction · 0.70
json_to_secretFunction · 0.50
json_get_memberFunction · 0.50
towire_tu64Function · 0.50

Tested by

no test coverage detected