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

Function htlc_accepted_call

plugins/keysend.c:342–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342static struct command_result *htlc_accepted_call(struct command *cmd,
343 const char *buf,
344 const jsmntok_t *params)
345{
346 const u8 *rawpayload;
347 struct sha256 payment_hash;
348 size_t max;
349 struct tlv_tlv_payload *payload;
350 struct tlv_field *preimage_field = NULL, *desc_field = NULL;
351 bigsize_t s;
352 struct keysend_in *ki;
353 struct out_req *req;
354 struct timeabs now = time_now();
355 const char *err;
356 u64 *allowed;
357 size_t err_off;
358 u64 err_type;
359
360 err = json_scan(tmpctx, buf, params,
361 "{onion:{payload:%},htlc:{payment_hash:%}}",
362 JSON_SCAN_TAL(cmd, json_tok_bin_from_hex, &rawpayload),
363 JSON_SCAN(json_to_sha256, &payment_hash));
364 if (err)
365 return htlc_accepted_continue(cmd, NULL);
366
367 max = tal_bytelen(rawpayload);
368
369 s = fromwire_bigsize(&rawpayload, &max);
370 if (s != max) {
371 return htlc_accepted_continue(cmd, NULL);
372 }
373
374 /* Note: This is a magic pointer value, not an actual array */
375 allowed = cast_const(u64 *, FROMWIRE_TLV_ANY_TYPE);
376
377 payload = tlv_tlv_payload_new(cmd);
378 if (!fromwire_tlv(&rawpayload, &max, tlvs_tlv_tlv_payload, TLVS_ARRAY_SIZE_tlv_tlv_payload,
379 payload, &payload->fields, allowed, &err_off, &err_type)) {
380 plugin_log(
381 cmd->plugin, LOG_UNUSUAL, "Malformed TLV payload type %"PRIu64" at off %zu %.*s",
382 err_type, err_off,
383 json_tok_full_len(params),
384 json_tok_full(buf, params));
385 return htlc_accepted_continue(cmd, NULL);
386 }
387
388 /* Try looking for the field that contains the preimage */
389 for (size_t i = 0; i < tal_count(payload->fields); i++) {
390 struct tlv_field *field = &payload->fields[i];
391 if (field->numtype == PREIMAGE_TLV_TYPE) {
392 preimage_field = field;
393 continue;
394 }
395
396 /* Longest (unknown) text field wins. */
397 if (!field->meta
398 && utf8_check(field->value, field->length)
399 && (!desc_field || field->length > desc_field->length))

Callers

nothing calls this directly

Calls 15

time_nowFunction · 0.85
htlc_accepted_continueFunction · 0.85
tal_bytelenFunction · 0.85
tal_hexstrFunction · 0.85
tal_freeFunction · 0.85
plugin_logFunction · 0.70
sha256Class · 0.70
send_outreqFunction · 0.70
json_scanFunction · 0.50
fromwire_bigsizeFunction · 0.50
fromwire_tlvFunction · 0.50
json_tok_full_lenFunction · 0.50

Tested by

no test coverage detected