| 346 | } |
| 347 | |
| 348 | static struct command_result * |
| 349 | htlc_accepted_invoice_created(struct command *cmd, |
| 350 | const char *method, |
| 351 | const char *buf, |
| 352 | const jsmntok_t *result, |
| 353 | struct keysend_in *ki) |
| 354 | { |
| 355 | struct tlv_field field; |
| 356 | |
| 357 | /* Remove all unknown fields: complain about unused even ones! |
| 358 | * (Keysend is not a design, it's a kludge by people who |
| 359 | * didn't read the spec, and Just Made Something Work). */ |
| 360 | for (size_t i = 0; i < tal_count(ki->payload->fields); i++) { |
| 361 | /* Odd fields are fine, leave them. */ |
| 362 | if (ki->payload->fields[i].numtype % 2) |
| 363 | continue; |
| 364 | /* Same with known fields */ |
| 365 | if (ki->payload->fields[i].meta) |
| 366 | continue; |
| 367 | /* If the type was explicitly allowed pass it through. */ |
| 368 | if (keysend_accept_extra_tlv_type(ki->payload->fields[i].numtype)) |
| 369 | continue; |
| 370 | /* Complain about it, at least. */ |
| 371 | if (ki->preimage_field != &ki->payload->fields[i]) { |
| 372 | plugin_log(cmd->plugin, LOG_INFORM, |
| 373 | "Keysend payment uses illegal even field %" |
| 374 | PRIu64 ": stripping", |
| 375 | ki->payload->fields[i].numtype); |
| 376 | } |
| 377 | tal_arr_remove(&ki->payload->fields, i); |
| 378 | i--; |
| 379 | } |
| 380 | |
| 381 | /* Now we can fill in the payment secret, from invoice. */ |
| 382 | ki->payload->payment_data = tal(ki->payload, |
| 383 | struct tlv_payload_payment_data); |
| 384 | json_to_secret(buf, json_get_member(buf, result, "payment_secret"), |
| 385 | &ki->payload->payment_data->payment_secret); |
| 386 | |
| 387 | /* We checked that amt_to_forward was non-NULL before */ |
| 388 | ki->payload->payment_data->total_msat = *ki->payload->amt_to_forward; |
| 389 | |
| 390 | /* In order to put payment_data into ->fields, I'd normally re-serialize, |
| 391 | * but we can have completely unknown fields. So insert manually. */ |
| 392 | /* BOLT #4: |
| 393 | * 1. type: 8 (`payment_data`) |
| 394 | * 2. data: |
| 395 | * * [`32*byte`:`payment_secret`] |
| 396 | * * [`tu64`:`total_msat`] |
| 397 | */ |
| 398 | field.numtype = 8; |
| 399 | field.value = tal_arr(ki->payload, u8, 0); |
| 400 | towire_secret(&field.value, &ki->payload->payment_data->payment_secret); |
| 401 | towire_tu64(&field.value, ki->payload->payment_data->total_msat); |
| 402 | field.length = tal_bytelen(field.value); |
| 403 | tal_arr_expand(&ki->payload->fields, field); |
| 404 | |
| 405 | asort(ki->payload->fields, tal_count(ki->payload->fields), |
nothing calls this directly
no test coverage detected