| 431 | } |
| 432 | |
| 433 | static struct command_result *htlc_accepted_call(struct command *cmd, |
| 434 | const char *buf, |
| 435 | const jsmntok_t *params) |
| 436 | { |
| 437 | const u8 *rawpayload; |
| 438 | struct sha256 payment_hash; |
| 439 | size_t max; |
| 440 | struct tlv_payload *payload; |
| 441 | struct tlv_field *preimage_field = NULL, *desc_field = NULL; |
| 442 | bigsize_t s; |
| 443 | struct keysend_in *ki; |
| 444 | struct out_req *req; |
| 445 | /* Even with CLN_DEV_SET_TIME, we need this to change */ |
| 446 | struct timeabs now = clock_time_progresses(); |
| 447 | const char *err; |
| 448 | u64 *allowed; |
| 449 | size_t err_off; |
| 450 | u64 err_type; |
| 451 | |
| 452 | err = json_scan(tmpctx, buf, params, |
| 453 | "{onion:{payload:%},htlc:{payment_hash:%}}", |
| 454 | JSON_SCAN_TAL(cmd, json_tok_bin_from_hex, &rawpayload), |
| 455 | JSON_SCAN(json_to_sha256, &payment_hash)); |
| 456 | if (err) |
| 457 | return htlc_accepted_continue(cmd, NULL); |
| 458 | |
| 459 | max = tal_bytelen(rawpayload); |
| 460 | |
| 461 | s = fromwire_bigsize(&rawpayload, &max); |
| 462 | if (s != max) { |
| 463 | return htlc_accepted_continue(cmd, NULL); |
| 464 | } |
| 465 | |
| 466 | /* Note: This is a magic pointer value, not an actual array */ |
| 467 | allowed = cast_const(u64 *, FROMWIRE_TLV_ANY_TYPE); |
| 468 | |
| 469 | payload = tlv_payload_new(cmd); |
| 470 | if (!fromwire_tlv(&rawpayload, &max, tlvs_tlv_payload, TLVS_ARRAY_SIZE_tlv_payload, |
| 471 | payload, &payload->fields, allowed, &err_off, &err_type)) { |
| 472 | plugin_log( |
| 473 | cmd->plugin, LOG_UNUSUAL, "Malformed TLV payload type %"PRIu64" at off %zu %.*s", |
| 474 | err_type, err_off, |
| 475 | json_tok_full_len(params), |
| 476 | json_tok_full(buf, params)); |
| 477 | return htlc_accepted_continue(cmd, NULL); |
| 478 | } |
| 479 | |
| 480 | /* Try looking for the field that contains the preimage */ |
| 481 | for (size_t i = 0; i < tal_count(payload->fields); i++) { |
| 482 | struct tlv_field *field = &payload->fields[i]; |
| 483 | if (field->numtype == PREIMAGE_TLV_TYPE) { |
| 484 | preimage_field = field; |
| 485 | continue; |
| 486 | } |
| 487 | |
| 488 | /* Longest (unknown) text field wins. */ |
| 489 | if (!field->meta |
| 490 | && utf8_check(field->value, field->length) |
nothing calls this directly
no test coverage detected